Work with Each Item in a List or Windows PowerShell Command Output
Problem
You have a list of items and want to work with each item in that list.
Solution
Use the ForeachObject cmdlet (which has the standard aliases foreach and %)to work with each item in a list.
To apply a calculation to each item in a list, use the $_ variable as part of a calculation in the scriptblock parameter:
PS >1..10 | ForeachObject { $_ * 2 } 2 4 6 8 10 12 14 16 18 20
To run a program on each file in a directory, use the $_ variable as a parameter to the program in the script block parameter: