ForEach Method

suggest change

Besides 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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents