Shutdown multiple PC's with Powershell

Hi All,

So I’m looking for a way to remote shutdown multiple windows PCs. I did post this initally on tenforums, but I think I will have better luck on this forum.

So far I have:
Stopped windows defender on both PC’s, changed execution policy to unrestricted on both PC’s, checked all services to make sure they are running, followed this guide:

Did have a RPC error until I disabled windows defender, I assume I will need to add ports once I get this working.

The issue I am having now is this:

attempted to add the -Credential prompt, but I am continuing to get the following error (tried with and without):
Stop-Computer : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\Users\Render 1\Documents\stopseanpc.ps1:1 char:1

  • Stop-Computer -ComputerName DESKTOP-P7D90PC -Credential DESKTOP-P7R59 …
  • CategoryInfo : NotSpecified: (:slight_smile: [Stop-Computer], UnauthorizedAccessExcepti
  • FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Comm

I’ve tried entering with and without quotations - unsure if this matters, but it doesn’t appear to.

Any ideas?


Either your account isn’t considered a local Administrator on the machine, or something on the machine is denying a shutdown (which is possible).

I’ve had more luck querying Win32_OperatingSystem from the remote computer, and executing the Win32Shutdown method. You can pass a parameter to not only shut down (or restart), but to FORCE the action, which is a bit stronger (in my experience) than what Stop-Computer does.

Hi Don,

Thanks for this. I’ve made sure my computer is a local administrator, still getting the same problem.

With the Win32_Operating System method, does the OS need to be Win32? Can you do multiple PC’s at once?

Is there someone in Microsoft that can help me with this as we have quite a few PC’s and I’ve spent quite some time working on this.


Sorry - didn’t realize you weren’t familiar with WMI.

Stop-Computer doesn’t do “multiple PCs at once;” internally, it enumerates them and does one at a time. Get-WmiObject and Invoke-WmiMethod do the same thing to any Windows computer (the “Win32” prefix in WMI is a legacy thing; it doesn’t denote a compatibility level).

I don’t have any ability to command Microsoft :). If you want their help, you probably need to open a support ticket. But they’re probably going to tell you pretty much what I have. WMI is worth the time to learn - it’s Microsoft’s official remote management technology for a lot of things (“Windows Management Instrumentation”), and PowerShell was built to leverage WMI pretty heavily.

Could you not have a list of computers in a file, create a pssession to each computer then run invoke-command against it? Something like this…

$session = get-content C:\scripts\computers.txt | new-pssession
invoke-command -session $session -scriptblock {restart-computer -force}

You certainly could. I use that exact example in most of my books, in fact.

-computername (Get-Content names.txt)

I probably got the idea from your book :wink: