Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Windows 10 / Shutdown/Restart Windows using Command Prompt and PowerShell

March 15, 2024 PowerShellQuestions and AnswersWindows 10Windows 11Windows Server 2019

Shutdown/Restart Windows using Command Prompt and PowerShell

Several commands are available in Windows that allow you to shutdown or restart a local or remote computer. In this article, we’ll look at how to use the shutdown command and the PowerShell cmdlets Restart-Computer and Stop-Computer to shutdown/restart Windows.

Contents:
  • Using the Shutdown Command on Windows
  • How to Shutdown or Restart a Remote Windows Computer?
  • Restart or Shutdown Windows with PowerShell

Using the Shutdown Command on Windows

The Shutdown.exe is a built-in Windows command line tool that allows you to reboot, shutdown, put your computer to sleep, hibernate, or end a user session. In this guide, we’ll show the basic examples of using the shutdown command in Windows. All commands discussed above are run in the Run dialog box — Win+R ->, in the command prompt (cmd.exe) or PowerShell.

The shutdown command has the following syntax: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e | /o] [/hybrid] [/soft] [/fw] [/f] [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]
The shutdown.exe command in Windows

As you can see, the command has quite a lot of options and can be used to shutdown/restart a local or remote computer.

How to shutdown windows from the command prompt

To shutdown Windows, use the shutdown command with the /s key.

shutdown /s

Reboot Windows from the CMD

To reboot your computer, use the /r parameter. After running it, Windows will be gracefully restarted.

shutdown /r

shutdown /r -reboot windows from cmd

End a User Session

To end the current user session (logoff), run this command

shutdown /l

shutdown /l - logoff current user

This command works in the same way as logoff.exe command.

How to hibernate Windows using the shutdown command?

To hibernate your computer, run this command:

shutdown /h

In the hibernate mode, all the contents of memory are written to the hiberfil.sys file on the local disk and the computer goes into sleep mode with reduced power consumption.

Notify logged-in users of an impending reboot or shutdown

You can notify all logged-on Windows users about the upcoming shutdown/reboot of the computer or server by sending a pop-up message to all active sessions. As a rule, this feature is used on RDS servers with several users working on them at the same time in their RDP sessions.

shutdown /r /c “This server will be restarted in 60 seconds.”

Delayed shutdown/reboot of a computer using the timer

You can shutdown or restart the computer with a certain delay (on a timer). Using the /t option, you can specify the time span after which the computer/server will be shutdown or rebooted. Thus you can provide your users some time to save open files and close the apps correctly. It is convenient to use this option together with the notification message. In this example, we inform the users that Windows will be shutdown in 10 minutes (600 seconds).

shutdown /s /t 600 /c "The server will be shutdown in 10 minutes. Save your work!"

A user will be warned about the scheduled shutdown:

You’re about to be signed out

windows shutdown command - You’re about to be signed out. Your Windows will shut down in 10 minutes

This command is useful for notifying users with sessions on RDSH hosts in a Remote Desktop Services farm on a Windows Server when you want to restart the server to perform maintenance. It can be used in conjunction with RDS Maintenance (Drain) Mode.

If the delay is too long (for example, 60 minutes/3,600 seconds), a pop-up window appears in the lower right corner of the screen:

You’re about to be signed out. Your Windows will shutdown in 100 minutes.

You’re about to be signed out. Your Windows will shut down in 100 minutes

How to stop/cancel/abort system shutdown in Windows

Windows waits 60 seconds by default without doing anything after running shutdown or reboot command.  An administrator can cancel the restart or shutdown of the device by running this command during this time:

shutdown /a

After you cancel the shutdown, you’ll see the following pop-up message in the lower right corner of the screen:

Logoff is cancelled. The scheduled shutdown has been cancelled.

Logoff is cancelled. The scheduled shutdown has been cancelled

Restart Windows immediately

To shutdown or reboot a computer immediately without waiting for 60 seconds, specify 0 as a value of the /t parameter. For example:

shutdown /r /t 0

The /f key is very important. I use it almost always when shutting down or restarting Windows Server hosts. This attribute allows to force close all running programs and processes without waiting for confirmation from the user (we won’t wait till the users confirm closing all applications on the RDS server since we can never get it).

The next command will restart the computer and automatically run all registered apps after reboot (apps registered in the system using RegisterApplicationRestart API are meant here).

shutdown /g

Create a restart shortcut on Windows Desktop

To make it more convenient for users, you can create a desktop shortcut to restart or shutdown a computer with the required parameters. Such a shortcut may be useful when you need to restart the computer from the RDP session when there are no options to restart or shutdown the computer in the Start menu.

shutdown shortcut

You can add such a shortcut to users’ computers using GPO.

How to restart Windows at a specific time (on schedule)?

If you want your computer or server to restart/shutdown at a specific time, you can add the shutdown command with the parameters to Windows Task Scheduler (taskschd.msc).

For example, this Scheduler task will restart the computer daily at 12 AM.

shedule a shutdown task

Or you can create a new Scheduler task with PowerShell:

$Trigger= New-ScheduledTaskTrigger -At 00:00am -Daily
$User= "NT AUTHORITY\SYSTEM"
$Action= New-ScheduledTaskAction -Execute "shutdown.exe" -Argument "–f –r –t 120"
Register-ScheduledTask -TaskName "RebootEvertyNight_PS" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest –Force

You can deploy the scheduled task to domain computers via Group Policy.

How to Shutdown or Restart a Remote Windows Computer?

You can use the shutdown.exe command to reboot a remote computer. To do this, the remote computer must be accessible over the network, and the account u you are using must be a member of the local Administrators group on the remote computer (server):

You can add domain users to the Administrators group via GPO.

shutdown /r /t 120 /m \\192.168.1.210

shutdown remote windows host

If all the conditions described above are met, but when running the shutdown command the error “Access denied (5)” appears, you need to allow remote access to the administrative shares (C$, ADMIN$) on the remote computer by changing the value of LocalAccountTokenFilterPolicy parameter to 1.

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v "LocalAccountTokenFilterPolicy" /t REG_DWORD /d 1 /f

Enable inbound WMI and SMB rules in Windows Defender Firewall on the remote computer to allow remote access using the shutdown.exe command.

You can enable these firewall rules using PowerShell:

Get-NetFirewallrule -name WMI-RPCSS-In-TCP,WMI-WINMGMT-In-TCP,FPS-SMB-In-TCP| Enable-NetFirewallRule

Or configure Windows Defender Firewall rules using GPO.

If you need to provide user credentials to connect to a remote computer, you can use the commands:

net use \\192.168.13.111 /u:corp\username
shutdown /s /t 60 /f /m \\192.168.13.111

If you need to restart multiple computers remotely, you can save the list of computers to a text file, and start a remote reboot of all computers using a simple PowerShell script:

$sh_msg = "Your computer will be automatically restarted in 10 minutes. Save your files and close running apps"
$sh_delay = 600 # seconds
$computers = gc C:\PS\PC-list.txt
foreach ($comp in $computers)
{
& 'C:\Windows\System32\SHUTDOWN.exe' "-m \\$comp -r -c $sh_msg -t $sh_delay"
}

Restart multiple computers with a Shutdowm.exe GUI

For those who don’t feel comfortable working in the command prompt, there is a graphical interface for the shutdown.exe command. To call the Remote Shutdown Dialog GUI, use the command:

shutdown /i

remote shutdown GIU dialog

As you can see, you can add multiple computers in the remote shutdown dialog to be rebooted/shutdown, specify the notification text, and specify the reason for the shutdown to be saved in the Windows event log.

Restart or Shutdown Windows with PowerShell

The following two commands are available in Windows PowerShell to shutdown and reboot the computer: Restart-Computer and Stop-Computer. Both commands allow you to shutdown or restart a local or remote computer (over the network).

powershell restart-computer cmdlet

To restart Windows, run:

Restart-Computer -force

To shutdown your computer:

Stop-Computer

By default, the reboot will start in 5 seconds. You can increase the delay before reboot:

Restart-Computer –Delay 60

Both cmdlets have a -ComputerName parameter that allows you to specify a list of remote computers to perform the action on.

For example, to shutdown two Windows servers remotely:

Stop-Computer -ComputerName "mun-srv01", "mun-srv02"

You can specify administrator credentials to connect to a remote host:

$Creds = Get-Credential
Restart-Computer -ComputerName mun-srv01-Credential $Creds

WMI and DCOM are used to connect to remote computers (they must be enabled and configured). If WMI is not configured, the following error will appear when running the command:

Restart-Computer : Failed to restart the computer wks-11222  with the following error message:
Access is denied.
Exception from HRESULT: 0x80070005 (E_ACCESSDENIED).

restart-computer: access is denied 0x80070005

If WinRM (Windows Remote Management) is enabled on the remote computer, you can use WSman instead of WMI to connect:

Restart-Computer -ComputerName wks-11222 -Protocol WSMan

If there are active user sessions on the remote computer, an error will appear:

Restart-Computer : Failed to restart the computer wks-11222  with the following error message:
The system shutdown cannot be initiated because there are other users logged on to the computer.

Restart-Computer : Failed to restart the computer The system shutdown cannot be initiated because there are other users logged on to the computer

You can find out the name of the currently logged on user on the remote computer with the command:

qwinsta /server:wks-11222  

To force a reboot, you need to add the -Force parameter:

Restart-Computer -ComputerName wks-11222 –Force

The event log entry with EventID 1074 (Event Viewer -> Windows Logs -> System) will contain the name of the user who shutdown/restarted Windows.

Event ID 1074 - who restarted windows

You can use the -For option to restart your computer and wait until it becomes available. For example, you want to make sure that the remote computer reboots successfully and the WinRM service is started on it, allowing you to connect to it through WS-Management:

Restart-Computer -ComputerName wks-11222 -Wait -For WinRM

Restarting computer wks-11222
Verifying that the computer has been restarted.

check that the remote computer restarted

You can wait for the Remote Desktop Service (RDP) or any other Windows service to start:

Restart-Computer -ComputerName wks-11222 -Wait -For TermService

If you need to restart multiple computers at the same time, you can use the parallel command execution available in PowerShell 7.x (see how to update PowerShell).

For example, you can get a list of Windows Servers hosts in a specific Active Directory container (Organizational Unit) using the Get-ADComputer cmdlet and restart them at the same time:

$Computers = (Get-ADComputer -Filter 'operatingsystem -like "*Windows server*" -and enabled -eq "true"' -SearchBase "OU=Servers,DC=woshub,DC=com").Name
$Computers | ForEach-Object -Parallel {    Restart-Computer -ComputerName $_ -Force} -ThrottleLimit 3

5 comments
4
Facebook Twitter Google + Pinterest
previous post
How to Create a Scheduled Task Using GPO
next post
How to Remove Hidden/Ghost Network Adapters in Windows

Related Reading

Configure NTP Time Source for Active Directory Domain

May 6, 2025

How to Cancel Windows Update Pending Restart Loop

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Change BIOS from Legacy to UEFI without Reinstalling...

April 21, 2025

Remove ‘Your License isn’t Genuine’ Banner in MS...

April 21, 2025

5 comments

dk June 14, 2024 - 10:02 am

I have a remote computer with the AnyDesk app installed. If I shutdown this machine via Start>Shutdown, I can turn it on remotely via Anydesk (maybe it uses Wake-on-LAN or something, I don’t know).
But when I turn off the PC with the shutdown command, I can’t turn it on remotely with AnyDesk. In other words, the shutdown command and the “Shutdown” item in the Start Menu have different results depending on the state of the computer when it is turned off.
Is it possible to use the Shutdown command to achieve the same state as the Shutdown item in the Start menu, so that you can turn it on after shutting it down?

Reply
kb June 14, 2024 - 10:36 am

The problem seems to be that, by default in Windows, when you shutdown the computer from the Start Menu, it goes into hibernation rather than a full shutdown. This is the default behavior if the Fast Startup option is enabled in the power plan settings.
Try to use the command:
shutdown /h
This will put the computer into hibernation mode.

Reply
Terry August 18, 2024 - 8:34 am

I’m stuck in a boot loop bringing me back to the blue “choose an option”, screen. I ran CMD and check disk found no issues. SFC did, but couldn’t fix and suggestions all state to rerun SFC 3-5 times, RESTARTING, after each attempt. However, there’s only an option to “shutdown your computer”, not restart.

My question, and I’ve been looking for hours now: from that RE, what is the CMD to restart from X: ?! Shutdown /r , amongst many others, comes back as unknown.

Reply
admin September 2, 2024 - 6:48 am

use the Wpeutil Reboot command to reboot in the Windows PE session

Reply
Aad aka 2733 October 12, 2024 - 12:36 pm

//
// RestartOrShutdown.cs, Aad Slingerland, oktober 2024.
// install-package System.Diagnostics.EventLog
// See also:
// _https://morgantechspace.com/2013/08/convert-datetime-to-ticks-and-ticks-to.html
// Limitations:
// English locale only, but the texts “restart” and “power off” can be changed to another locale.
//
using System.Diagnostics;

namespace RestartOrShutdown;

internal class Program
{
static int Main(string[] args)
{
int rc = 0;
int minutes = 1;
try
{
if (args.Length > 0)
{
minutes = int.Parse(args[0]);
}
#pragma warning disable CA1416 // Validate platform compatibility
EventLog syslog = new(“System”);
//
DateTime _now = DateTime.Now;
long minus = 10000000; // one second in ticks
DateTime _past = _now.AddTicks(-(minus * 60 * minutes));
//
Debug.WriteLine(_now.Ticks);
Debug.WriteLine(_past.Ticks);
//
var entries = syslog.Entries.Cast()
.Where(x => x.TimeWritten.Ticks > _past.Ticks && x.EventID == 1074)
.ToList();
#pragma warning restore CA1416 // Validate platform compatibility
//
foreach (EventLogEntry e in entries)
{
Debug.WriteLine(e.TimeWritten.Ticks);
Debug.WriteLine(e.Message);
if (e.Message.Contains(“restart”))
{
rc = 1;
}
else if (e.Message.Contains(“power off”))
{
rc = 2;
}
}
}
catch (System.FormatException)
{
Usage();
rc = 0;
}
Console.WriteLine($”Returncode={rc}”);
return rc;
}

static void Usage()
{
Console.WriteLine(@”
Usage: RestartOrShutdown [minutes]

Queries the Operating System wether it is in the process of Restart or Shutdown.
Return code 0 = neither.
Return code 1 = Restarting in progress.
Return code 2 = Shutdown in progress.
Return code 9 = invalid argument value.
The argument [minutes] defaults to 1 minute.
The argument [minutes] tells this program how far to look back in the Windows
System Event log for a record with EventID 1074.”);
}
}

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Install and Manage Windows Updates with PowerShell (PSWindowsUpdate)
  • How to Download Offline Installer (APPX/MSIX) for Microsoft Store App
  • Fix: Remote Desktop Licensing Mode is not Configured
  • How to Delete Old User Profiles in Windows
  • Configuring Port Forwarding in Windows
  • How to Install Remote Server Administration Tools (RSAT) on Windows
  • Start Menu or Taskbar Search Not Working in Windows 10/11
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top