Link to home
Start Free TrialLog in
Avatar of Alex
AlexFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Limit script to only reboot 20 machines at a time

Good morning,

$Computers = Get-ADComputer -Filter * -searchbase "OU=branch,DC=net,DC=Company,DC=co,DC=uk" | Where-Object {$_.Name -like "*TM*"} | Select -Property Name

ForEach ($Computer in $Computers) {
	If (Test-Connection -ComputerName $Computer -Quiet) {
		& shutdown.exe -m "\\$($Computer)" /f /R
	} Else {
		"$($Computer) is not online" | Out-File -Append "C:\Powershell Projects\reboot script\computersnotonline.txt"
	}
}

Open in new window


Right, so this works fine, it enumerates the machines with the correct names from the specified OU.

How can I make it limit the reboot to 20 and wait 20 seconds until each machine is back up?

Thanks

Alex
ASKER CERTIFIED SOLUTION
Avatar of Benjamin MOREAU
Benjamin MOREAU
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Alex

ASKER

Thanks