How to shut down computer with PowerShell?

Viewed 2898

I would like to do shutdown process in my script. I use Stop-Computer. But it always reboots, doesn't shut down. I tried stop-computer alone, it works, but when I applied it to my script, it reboots, doesn't shut down, can anyone give any idea please?

4 Answers

Refer to stop-computer, you can use -Force to force an immediate shut down of the computer.


stop-computer -computername localhost -Force

The Stop-Computer cmd lets you shuts down the local computer and remote computers(if any)

You can use the parameters of Stop-Computer to specify the authentication levels and alternate credentials, and to force an immediate shut down.

to shut down your local machine -

Stop-Computer -ComputerName localhost

-ComputerName Specifies the computers to stop. The default is the local computer.

Using `shutdown.exe:

shutdown.exe /s /f

If you want to shut down computer on Workgroup environment.

Scenario: You want to shut down computer named HP-ZBook from your computer named PC1

Step-1:On PC1 => Start Powershell in admin mode

Step-2:On PC1 => Run command to check if HP-ZBOOK is in trusted host list of PC1

Get-Item WSMan:\localhost\Client\TrustedHosts

Step-3:On PC1 Run command to add HP-ZBOOK to trusted host list of PC1

Set-Item WSMan:\localhost\Client\TrustedHosts -Value 'HP-ZBOOK'

enter image description here

Step-4:On HP-ZBOOK => Start powershell in admin mode

Step-5:On HP-ZBOOK run below command to start WinSRM service and Enable WinRM firewall Exception

WinRM QuickConfig

enter image description here

Step-6:On PC1 Run command to shutdown computer HP-ZBOOK

   Stop-Computer -ComputerName HP-ZBook -force

enter image description here

Related