ForEach Method
suggest changeBesides the ForEach-Object cmdlet, collections have a ForEach method (Windows PowerShell 4.0 and later):
(1..10).ForEach({$_ * $_})
or - if desired - the parentheses around the script block can be omitted
(1..10).ForEach{$_ * $_}
Both will result in the output below
1
4
9
16
25
36
49
64
81
100
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents