The ForEach-Object command

ForEach-Object is most often used as a loop (of sorts). For example, the following command works on each of the results from Get-Process in turn:

Get-Process | ForEach-Object { 
    Write-Host $_.Name -ForegroundColor Green 
} 

In the preceding example, a special variable, $_, is used to represent each of the processes in turn.

ForEach-Object may also be used to get a single property, or execute a single method on each of the objects. For example, ForEach-Object may be used to return only the Path property when using Get-Process:

Get-Process | ForEach-Object Path 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.67.5