Reboot a computer remotely with WMI and PowerShell
One of the trickiest things to do when working with computes remotely is reboot them. We also have to make sure that the computers don’t have any bios issues that can cause them to not restart. Many times we can’t even get logged on if their Terminal Services access is shut off. With this trick you can reboot a server with ease, even one that doesn’t have PowerShell installed.
To do this first we get on a computer that does have PowerShell. At the PowerShell prompt, try:
PS C:\> $your_server = gwmi win32_operatingsystem -computer yourservername
If you follow best practices and do not run under a domain admin account, (or an account that is local admin on all your servers) Then you should see an error like this:
Now we want to be able to shutdown a computer, but we need to make sure we’re using an account with permissions to reboot the computer in question.
You can use the runas CMD command to launch a PowerShell with the necessary credential.
PS C:\>runas /env /user:administrator@domain.local “powershell.exe”
Then you will be able to link the other computer to your variable, and fire off the simple reboot method.
PS C:\>$your_server = gwmi win32_operatingsystem -computer yourservername
…
Click to continue reading "Reboot a computer remotely with WMI and PowerShell"
Written by daniel.nerenberg on May 18th, 2007 with no comments.
Read more articles on PowerShell.















