Why don't you just assign the result to a variable?
$d = @(Get-Whatever -dep $department); $d Write-Host $d.Count records found
Pay attention to @(..) . This ensures that even when Get-Whatever returns nothing, $d will be an empty array.
Another way is, for example, Tee-Object . However, it creates variables βmagicallyβ somewhat, therefore it is not as readable as the first approach:
Get-ChildItem | Tee-Object -var items Write-Host $items.Count items found
Regarding Tee-Object (from the documentation, try help tee-object -online ):
The Tee-Object cmdlet sends the result of a command in two directions (for example, the letter "T"). It saves the output in a file or variable, and also pipes it. If Tee-Object is the last command in the pipeline, the output of the command is displayed in the console.
source share