Iterate systems with a timer
-
I needed to iterate through a list of systems that I'd placed in to a text file so I could shut them off, perform work on each one through vsphere and return it to service without just taking them all down immediately. The countdown gives me the opportunity to do the work and turn the vm back on.
$file = "$($ENV:USERPROFILE)\desktop\systems.txt" $systems = get-content $file foreach ($guest in $Systems){ Write-Host -foregroundcolor cyan "``nStopping $($guest)." Stop-Computer -ComputerName $guest #On-screen Timer $delay = 280 $Counter_Form = New-Object System.Windows.Forms.Form $Counter_Form.Text = "Countdown Timer!" $Counter_Form.Width = 450 $Counter_Form.Height = 200 $Counter_Label = New-Object System.Windows.Forms.Label $Counter_Label.AutoSize = $true $Counter_Form.Controls.Add($Counter_Label) while ($delay -ge 0) { $Counter_Form.Show() $Counter_Label.Text = "Seconds Remaining: $($delay)" start-sleep 1 $delay -= 1 } $Counter_Form.Close() }
Recorded here for future use and/or sharing. Counter from here.