add a catch block
Otherwise the script doesn't work properly if you don't have the permissions to restart the computer remotely
This commit is contained in:
parent
23314a2dcd
commit
46013c0130
|
@ -1,7 +1,9 @@
|
|||
function Restart-Domain-Computer
|
||||
{
|
||||
try
|
||||
{
|
||||
$computername = Read-Host 'Please enter a computer name'
|
||||
Restart-Computer -Force -ComputerName $computername
|
||||
Restart-Computer -Force -ComputerName $computername -ErrorAction Stop
|
||||
sleep 30
|
||||
while ($status -eq $null)
|
||||
{
|
||||
|
@ -16,6 +18,13 @@ function Restart-Domain-Computer
|
|||
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
|
||||
}
|
||||
}
|
||||
|
||||
Restart-Domain-Computer
|
||||
|
|
Reference in New Issue