wolfgang ziegler


„make stuff and blog about it“

Remote Reboot / Shutdown using PowerShell

June 11, 2012

We’re going to use the Win32_OperatingSystem WMI class to do this. Specifically we’ll be using the Win32Shutdown method.

The method takes a single parameter to determine exactly what should be done:

0 = Log off 4 = Forced log off 1 = Shutdown 5 = Forced shutdown 2 = Reboot 6 = Forced reboot 8 = Power off 12 = Forced power off

Here are a couple of examples for using this method.

Log off the local computer:

(gwmi Win32_OperatingSystem).Win32Shutdown(0)

Restart a remote computer:

(gwmi win32_operatingsystem -ComputerName MyComputer).Win32Shutdown(6)

Restart a remote computer using alternate credentials:

(gwmi win32_operatingsystem -ComputerName MyComputer -cred (get-credential)).Win32Shutdown(6)