Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Foreach loop

$
0
0

The pipeline is PowerShell’s primary means of streaming objects instead of holding an entire result set in memory. If that’s your goal, you’ll need to stop avoiding the pipeline completely.

That said, you can put multiple commands into a script block and invoke it like a single command, piping the results to another command (ForEach-Object, or whatever.) This accomplishes what you were trying to do:

$scriptBlock = {
    Get-MailUser
    Get-MailBox 
}

& $scriptBlock |
ForEach-Object {
    # Do something
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles