I'm trying to write a script to reboot Macs in a range of IP addresses. Doing it through PowerShell works, but the process waits until each machine reboots before it moves on to the next machine. I'm finding ssh
'ing into each machine and rebooting it using sudo shutdown -S shutdown -r now
is faster...it's just manual. Here's what I have so far in PowerShell:
$serverRoot = "xxx.xxx.xxx."
$startVal = 100
$stopVal = 150
for ($i=$startVal; $i -le $stopVal; $i++)
{
$User="username"
$Password="password"
$SecurePass=ConvertTo-SecureString -string $Password -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential $User, $SecurePass
$session = New-SSHSession -ComputerName ($serverRoot + $i) -Credential $Credential -AcceptKey
Invoke-SSHCommand -SSHSession $session -Command "echo $Password | sudo -S shutdown -r now"
Remove-SSHSession -SSHSession $session -Verbose
}
Is there something I can add which will just kick the reboot process off on all the machines at once? Should I use AppleScript?