How to Shut Down a Computer Using PowerShell (Stop-Computer)

To shut down a computer with PowerShell, run Stop-Computer. With no parameters it turns off the local computer right away, and -ComputerName points it at other machines:

Stop-Computer
Stop-Computer -ComputerName NYC-WEB01, DEN-SQL02 -Force

In this tutorial, I’ll show you how to shutdown computer PowerShell style: the local PC, a list of remote servers, a delayed or scheduled shutdown, and the parameters that only exist in Windows PowerShell 5.1.

I wrote this on the PC I work on, so every Stop-Computer command I ran has -WhatIf. It prints what would happen and changes nothing. Remove -WhatIf only when you’re ready for the machine to turn off.

How to shut down the local computer with Stop-Computer

Stop-Computer without -ComputerName targets the computer you’re on. Typing localhost does the same thing. Here are both, as a safe preview:

Stop-Computer -WhatIf
Stop-Computer -ComputerName localhost -WhatIf

Output:

What if: Performing the operation "Stop-Computer" on target "localhost (DESKTOP-4T7K2QX)".
What if: Performing the operation "Stop-Computer" on target "localhost (DESKTOP-4T7K2QX)".

The target reads localhost plus the computer name, which I replaced with DESKTOP-4T7K2QX. You can confirm yours first when you get the computer name in PowerShell.

Without -WhatIf, Stop-Computer doesn’t print anything; Windows starts shutting down. Open apps get the normal chance to close, and one with unsaved work can hold the shutdown up.

Add -Force to close apps without waiting. Microsoft describes it as forcing “an immediate shut down,” so unsaved files are lost. Use it on servers and hung machines, not on a desktop where someone is still typing.

Need the machine back up afterward? That’s a different cmdlet, covered in my guide to restart a computer using PowerShell.

Stop-Computer parameters in PowerShell 7 vs Windows PowerShell 5.1

The cmdlet has the same name in both versions, but PowerShell 7 dropped most of its parameters. This lists the cmdlet’s own parameters, minus the common ones every cmdlet has:

$common = [System.Management.Automation.PSCmdlet]::CommonParameters +
          [System.Management.Automation.PSCmdlet]::OptionalCommonParameters
$own = (Get-Command -Name Stop-Computer).Parameters.Keys | Where-Object { $_ -notin $common }
"PowerShell $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor): $($own.Count) parameters"
$own -join ', '

Output:

PowerShell 7.6: 4 parameters
WsmanAuthentication, ComputerName, Credential, Force

The output above is from PowerShell 7, which keeps four. Windows PowerShell 5.1 lists nine, adding AsJob, DcomAuthentication, Protocol, Impersonation and ThrottleLimit:

Stop-Computer parameters listed in Windows PowerShell 5.1
Five Stop-Computer parameters exist only in Windows PowerShell 5.1 (Windows PowerShell 5.1)

A 5.1 script that passes one of them breaks in PowerShell 7. Here’s -Protocol WSMan, again with -WhatIf:

try {
    Stop-Computer -Protocol WSMan -WhatIf -ErrorAction Stop
}
catch {
    "Failed. $($_.Exception.Message)"
}

Output:

Failed. A parameter cannot be found that matches parameter name 'Protocol'.

PowerShell 7 rejected the parameter, as shown above. Windows PowerShell 5.1 accepted it and printed the usual “What if”