# Script to Shut Down Windows devices

Shutting down a Windows device ensures energy efficiency, component longevity, and resolves persistent hardware issues. A shutdown guarantees a complete power cycle. The heat stress on internal components such as CPU, GPU, hard drives etc. due to long periods of idle or sleep mode is also minimized. Shutting down a device remotely can help administrators with troubleshooting and correcting boot-related conflicts as the device truly goes offline, before the next booting. Hexnode UEM allows admins to run custom scripts to shut down or schedule shutdown of Windows devices using [Execute Custom Script](https://www.hexnode.com/mobile-device-management/help/executing-custom-scripts-for-windows/) action, remotely. In this article, both PowerShell and Batch scripts are provided to perform shutdown.

 Supported Versions: 
The scripts are supported for execution on the following Windows versions:

- Windows 10 v1803+
- Windows 10 v1703 to Windows 10 v1709 (if .NET Framework v4.7.1+ is installed on the device)
- Windows 11 (Pro, Enterprise, Education)

 

 Warning 
The sample scripts provided below are adapted from third-party open-source sites.

 

Batch scripts
-------------

1. #### Shutting down the device immediately
    
    Batch script to shut down Windows
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shutdown.exe /s /t 00 
    
       1
    
    
    
      shutdown.exe /s /t 00 
    
    
    
       
    
     
    
      
    
    Once the command is executed, the device shuts down after displaying a warning message.
2. #### Scheduling the shutting down of the device
    
    Batch script to shut down Windows with delay
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    shutdown.exe /s /t 15 
    
       1
    
    
    
      shutdown.exe /s /t 15 
    
    
    
       
    
     
    
     
    
    By customizing the parameter `/t`, you can schedule shutdown to proceed after the specified number of seconds.Here, an example has been provided to shut down the device in 15 seconds.
![Schedule a shut down on Windows devices](https://cdn.hexnode.com/mobile-device-management/help/wp-content/uploads/2021/09/script-to-schedule-shut-down-on-Windows.png)

Powershell script
-----------------

Batch script to shut down Windows

Stop-Computer -ComputerName "computer\_name" -force 

   1

  Stop-Computer -ComputerName "computer\_name" -force 

   

 

  

The `Stop-Computer` cmdlet is used to shutdown the device. Replace `computer_name` with the name or IP address of the device that needs to be shutdown.`-force` compels the device to shut down without prompting confirmation.

 Notes:- It is recommended to manually validate the script execution on a system before executing the action in bulk.
- Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.