Powershell Function to Reboot a Computer with Warning Messages

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]


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *