diff --git a/scripts/computers/restart-computer.ps1 b/scripts/computers/restart-computer.ps1 index de115a0..5351969 100644 --- a/scripts/computers/restart-computer.ps1 +++ b/scripts/computers/restart-computer.ps1 @@ -1,21 +1,30 @@ function Restart-Domain-Computer { - $computername = Read-Host 'Please enter a computer name' - Restart-Computer -Force -ComputerName $computername - sleep 30 - while ($status -eq $null) + try { - if(Test-Connection -Computername $computername ` - -BufferSize 16 ` - -Count 1 ` - -Quiet){break} - Write-Host 'Still offline' - sleep 5 + $computername = Read-Host 'Please enter a computer name' + Restart-Computer -Force -ComputerName $computername -ErrorAction Stop + sleep 30 + while ($status -eq $null) + { + if(Test-Connection -Computername $computername ` + -BufferSize 16 ` + -Count 1 ` + -Quiet){break} + Write-Host 'Still offline' + sleep 5 + } + Write-Host + Write-Host -backgroundcolor "green" $computername ' is online' + Write-Host + Read-Host 'Press a key to quit' + } + catch + { + Write-Warning $_ + Read-Host 'Press a key to quit' + break } - Write-Host - Write-Host -backgroundcolor "green" $computername ' is online' - Write-Host - Read-Host 'Press a key to quit' } Restart-Domain-Computer