I am trying to write a script to reboot a Mac in a range of IP addresses. Doing this with PowerShell works, but the process waits until each machine reboots before it moves on to the next machine. I find ssh'in every machine, and rebooting with sudo shutdown -S shutdown -r nowis faster ... it's just an instruction. Here is what I still have 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 that just shuts down the reboot process on all computers at once? Should I use AppleScript?
source
share