Hi, Damian Garbus here and this is Poshland blog about PowerShell. Several posts ago I wrote about the best reason to learn PowerShell. Today I want to show you fast tips to understanding PowerShell “
What is loop in programming?
Powershell “
Why is Powershell “Foreach” better
When you want to write step by step for changing tires it will look like this.
Write-Host "Unscrew Front Left Wheel"
Write-Host "Change tire"
Write-Host "Fix Front Left Wheel"
Write-Host "Unscrew Front Right Wheel"
Write-Host "Change tire"
Write-Host "Fix Front Right Wheel"
Write-Host "Unscrew Rear Left Wheel"
Write-Host "Change tire"
Write-Host "Fix Rear Left Wheel"
Write-Host "Unscrew Rear Right Wheel"
Write-Host "Change tire"
Write-Host "Fix Rear Right Wheel"

When you use “
$MyWheels = "Front Left Wheel", "Front Right Wheel", "Rear Left Wheel","Rear Right Wheel"
foreach ($wheel in $MyWheels) {
Write-Host "Unscrew $wheel"
Write-Host "Change tire"
Write-Host "Fix $wheel"
}

What when you have two cars
When you have two cars we can use another variable to define all of your cars and use a loop within loop.
But
Write-Host "Unscrew Lamborghini Front Left Wheel"
Write-Host "Change tire"
Write-Host "Fix Lamborghini Front Left Wheel"
Write-Host "Unscrew Lamborghini Front Right Wheel"
Write-Host "Change tire"
Write-Host "Fix Lamborghini Front Right Wheel"
Write-Host "Unscrew Lamborghini Rear Left Wheel"
Write-Host "Change tire"
Write-Host "Fix Lamborghini Rear Left Wheel"
Write-Host "Unscrew Lamborghini Rear Right Wheel"
Write-Host "Change tire"
Write-Host "Fix Lamborghini Rear Right Wheel"
Write-Host "Unscrew Porshe Front Left Wheel"
Write-Host "Change tire"
Write-Host "Fix Porshe Front Left Wheel"
Write-Host "Unscrew Porshe Front Right Wheel"
Write-Host "Change tire"
Write-Host "Fix Porshe Front Right Wheel"
Write-Host "Unscrew Porshe Rear Left Wheel"
Write-Host "Change tire"
Write-Host "Fix Porshe Rear Left Wheel"
Write-Host "Unscrew Porshe Rear Right Wheel"
Write-Host "Change tire"
Write-Host "Fix Porshe Rear Right Wheel"

And now with “Foreach” loop.
$MyCars = "Lamborghini","Porshe"
$MyWheels = "Front Left Wheel", "Front Right Wheel", "Rear Left Wheel","Rear Right Wheel"
foreach ($car in $MyCars) {
foreach ($wheel in $MyWheels) {
Write-Host "Unscreew $car $wheel"
Write-Host "Change tire"
Write-Host "Fix $car $wheel"
}
}

Conclusion
I hope this post helps you to understand