PowerShell: Loop Cheat Sheet

# Do While Loop
$a=1
Do {$a; $a++}
While ($a –lt 10)
# Do Until Loop
$a=1
Do {$a; $a++}
Until ($a –gt 10)
# For Loop
For ($a=1; $a –le 10; $a++)
{$a}
# ForEach – Loop Through Collection of Objects
Foreach ($i in Get-Childitem c:\windows)
{$i.name; $i.creationtime}

Leave a Reply

Your email address will not be published. Required fields are marked *