How to shutdown or restart the computer in Windows PowerShell

Information

The Windows operating system has many different ways to shut down or restart your computer. For example, you can shut down or restart your computer using Start menu, WinX menu, command prompt, Run window, Windows Shutdown window by pressing Alt + F4 or by creating a special shortcut, etc.

To shut down the computer, run Windows PowerShell as administrator and run the following command:

Stop-Computer

To reboot your computer, run Windows PowerShell as administrator and run the command:

Restart-Computer

You can also use the Win32Shutdown method from the Win32_OperatingSystem WMI class to shutdown or reboot. Flags from the list below can be used as an argument:

  • 0 – Log Off
  • 4 – Forced Log Off
  • 1 – Shutdown
  • 5 – Forced Shutdown
  • 2 – Reboot
  • 6 – Forced Reboot
  • 8 – Power Off
  • 12 – Forced Power Off

Let’s look at some examples of commands. To shut down your computer, run the command:

(Get-WmiObject Win32_OperatingSystem -EnableAllPrivileges).Win32Shutdown(1)

To reboot your computer, run the command:

(Get-WmiObject Win32_OperatingSystem -EnableAllPrivileges).Win32Shutdown(2)

To log out, run the command:

(Get-WmiObject Win32_OperatingSystem -EnableAllPrivileges).Win32Shutdown(0)

And as an addition, a few different commands for shutting down and restarting the computer using the Windows PowerShell console.

With the following command you can shut down two remote computers at the same time:

Stop-Computer -ComputerName “Server01”, “Server02”

The following command demonstrates how to reboot two remote computers named Server01 and Server02 and a local computer identified as localhost.

Restart-Computer -ComputerName “Server01”, “Server02”, “localhost”

With the following command, you can set the delay time (in seconds) before the computer shuts down.

Start-Sleep -Seconds 60; Stop-Computer

The following command sets the time (in seconds) before the computer reboots.

Start-Sleep -Seconds 60; Restart-Computer

For more help on the Restart-Computer cmdlet, visit the Microsoft Web site at this ➯ link, and for help on the Stop-Computer cmdlet, see ➯ here. That’s all for now.

Rate article
Windows 10, Microsoft news, device reviews, registry and tweaks
Add a comment