Loops may be used to iterate through collections, performing an operation against each element in the collection, or to repeat an operation (or series of operations) until a condition is met.
Loops
foreach
The foreach loop executes against each element of a collection using the following notation:
foreach (<element> in <collection>) { <body-statements> }
For example, the foreach loop may be used to iterate through each of the processes returned by Get-Process:
foreach ($process in Get-Process) { Write-Host $process.Name }
If the collection is $null or empty, the body of the loop will not execute.