Powershell Function to Reboot a Computer with Warning Messages

I am fully aware that a simple

Restart-Computer "ServerName"

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.

Function Reboot-Computer
	param([String[]]$ComputerName = $env:COMPUTERNAME)
	Write-Host "WARNING: YOU ARE TRYING TO REBOOT COMPUTER(S): $ComputerName!" -ForegroundColor "Yellow" 
	Restart-Computer -ComputerName $ComputerName -Confirm  

About Nick Xu

Not a DBA anymore
This entry was posted in Powershell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s