Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Restart Windows Server with PowerShell

Restart a local or remote Windows Server with the Restart-Computer cmdlet.

Windows Hosting2 min read6 screenshots

Before you start

1. Administrator rights

Open PowerShell as Administrator (right-click it and choose Run as administrator).

2. Execution policy

Check the policy that controls scripts:

Get-ExecutionPolicy
Checking the execution policy

If it is Restricted, you cannot run scripts. Restart-Computer is a cmdlet and works anyway, but scripts need a looser policy:

Set-ExecutionPolicy RemoteSigned
Setting the execution policy

3. PowerShell remoting (for remote servers)

To restart a remote server, enable remoting on it:

Enable-PSRemoting -Force
Enabling PowerShell remoting

Restart the local server

Restart-Computer
Restarting the local computer

Useful options

Force the restart even if users are logged on or programs are open:

Restart-Computer -Force
Forcing a restart

Ask for a confirmation:

Restart-Computer -Confirm
Asking for a confirmation

Show what would happen without doing it:

Restart-Computer -WhatIf

Restart a remote server

Restart-Computer -ComputerName "Server01"

With other credentials:

Restart-Computer -ComputerName "Server01" -Credential (Get-Credential)

Several servers at once:

Restart-Computer -ComputerName "Server01","Server02" -Force

Wait until a remote server is back before the script goes on:

Restart-Computer -ComputerName "Server01" -Wait -For PowerShell -Timeout 300

Other ways

The classic command also works in PowerShell or Command Prompt:

shutdown /r /t 0

/r restarts and /t 0 sets zero seconds of delay.

Warning: A forced restart can lose unsaved data. Use it when you must, and warn the users first.

Quick recap

  • Run Restart-Computer as administrator.
  • Add -ComputerName for a remote server and -Force to close programs.