The following useful information is primarily taken from the Windows PowerShell Language Quick Reference (QuadFold.rtf) documentation.
For
Format:
1[:label] for ([initializer]; [condition]; [iterator]) {}
Example:
1for ($i=0; $i -lt 5; $i++) { Write-Object $i }
For Each
Format:
1[:label]
2
3foreach (identifier in collection) {}
4
5Expression | foreach {}
6
7Expression | foreach {BEGIN{} PROCESS{} END{}}
Examples:
1$i = 1,2,3
2foreach ($z in $i) { Write-Object $z }
3
4Get-Process | foreach {
5 BEGIN{$x=1}
6 PROCESS{$X++}
7 END{"$X Processes"}
8}
Do Until
1do
2{
3 ...
4} until (condition)
While
1[:label] while (condition)
2{
3 ...
4}
Do While
1do
2{
3 ...
4} while (condition)
comments powered by Disqus