When obtaining data using PowerShell, sometimes we want it displayed to the screen. Sometimes we want it saved to a variable.
But if we use Tee-Object, we can do both:
Get-Process | Select-Object Name -First 1 | `
Tee-Object -Variable FirstProcess
In this command, we're getting all the processes running on the computer. Then we pipe it to the Select-Object command to pick out the first one alphabetically. Then we pipe it to the Tee-Object, which both prints it to the screen and populates the variable $FirstProcess with the value.
No comments:
Post a Comment