Online Test Banks
Score higher
See Online Test Banks
eLearning
Learning anything is easy
Browse Online Courses
Mobile Apps
Learning on the go
Explore Mobile Apps
Dummies Store
Shop for books and more
Start Shopping

Performing Loops in Windows PowerShell 2

Part of the Windows PowerShell 2 For Dummies Cheat Sheet

As you automate your Windows operating system with PowerShell 2, you can automate some of the script you need as well. Loops run the same script block multiple times — often on changing values. A few examples follow:

for ($i = 1; $i -le 5; $i++) { Write-Host $i }
foreach ($i in Get-Alias) { Write-Host $i.name }
$i = 1
while ($i -lt 7) {
     Write-Host $i++
}
$i = 1
do
{
     Write-Host $i++
} while ($i -lt 7)
blog comments powered by Disqus
Advertisement

Inside Dummies.com

Dummies.com Sweepstakes

Win $500. Easy.