I am fully aware that a simple [sourcecode language=”powershell”]Restart-Computer "ServerName"[/sourcecode] command can easily do the trick, but it means doing this trick a bit too easy and too harzardly. I’d like to see my own function to promt up some warnings and confirmations before I actually do the reboot. I learned this lesson by typing a typo yesterday and accidentally restarting another (fortunately dev) box.
[sourcecode language=”powershell”]
Function Reboot-Computer
{
param([String[]]$ComputerName = $env:COMPUTERNAME)
Write-Host "WARNING: YOU ARE TRYING TO REBOOT COMPUTER(S): $ComputerName!" -ForegroundColor "Yellow"
Write-Host "PLEASE CONFIRM THAT YOUR ACTION IS WELL-INTENTIONED!" -ForegroundColor "Red"
Restart-Computer -ComputerName $ComputerName -Confirm
}
[/sourcecode]
Leave a Reply