Collections:
Other Resources:
Execution Loops in Windows PowerShell Scripts
How to write execution loops in Windows PowerShell scripts? I want to repeat some code multiple times.
✍: FYIcenter.com
There are several ways to write execution loops in Windows PowerShell scripts.
1. "While {...}" loop - For example:
$today = Get-Date
"Today is "+$today.DayOfWeek
$next = $today.AddDays(1)
While ($next.DayOfWeek -ne $today.DayOfWeek) {
"Next day is "+$next.DayOfWeek
$next = $next.AddDays(1)
}
2. "Do {...} While" loop - For example:
$today = Get-Date
"Today is "+$today.DayOfWeek
$next = $today
Do {
$next = $next.AddDays(1)
"Next day is "+$next.DayOfWeek
} While ($next.DayOfWeek -ne $today.DayOfWeek)
3. "Do {...} Until" loop - For example:
$today = Get-Date
"Today is "+$today.DayOfWeek
$next = $today
Do {
$next = $next.AddDays(1)
"Next day is "+$next.DayOfWeek
} Until ($next.DayOfWeek -eq $today.DayOfWeek)
4. "For (...) {...}" loop - For example:
$today = Get-Date
"Today is "+$today.DayOfWeek
$next = $today
For ($i=0; $i -lt 6; $i++) {
$next = $next.AddDays(1)
"Next day is "+$next.DayOfWeek
}
⇒ Array in Windows PowerShell Scripts
⇐ Console Input and Output in Windows PowerShell Scripts
2016-10-29, ∼2599🔥, 0💬
Popular Posts:
Extracting All Files from a ZIP File 1. Run WinZIP and select menu File > Open Archive. The "Open Ar...
How to verify IIS configuration for PHP scripts? If you have followed our Configuring IIS for PHP Sc...
Where to find tutorials on using Edge Web browser. Here is a collection of tutorials on Edge Web bro...
Can I remove startup application "shstat.exe - VirusScan On-access scanner statistics" to speedup my...
Signing in on my computer that doesn't run 8 works just fine. So must be windows eight that is causi...