I wanted to be able to just tell all the servers I work with to shutdown instead of having to Remote Desktop into the server and shutdown or to hold the power button down (Gasp!)
$cred = Get-Credential -Credential "Domain\SomeoneWithPermissions" Write-Host "Shutting Down <serverNameHere>" $server = Get-WmiObject "Win32_OperatingSystem" -ComputerName "ServerName" -Credential $cred $server.Shutdown()
The first line specifies that you want to get the credentials of a given domain account and assign it to the $cred variable.
The second line just writes a message… I chose for it to write “Shutting down whateverTheServerNameis”
The third line get the WMI Object that will be used to communicate with the server specified by -ComputerName using the Credentials we stored in the $cred variable
The last line called shutdown on that objects, which calls the server/computer and tells it to shutdown nicely.
Note that when you run this you will get a dialog asking for the password of the account! you could also put that in but it would be a bit funny normally to put the password of such a powerful account into a text file… :S