Author Posts

July 11, 2018 at 4:18 pm

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:
https://www.drivereasy.com/knowledge/rpc-server-is-unavailable-error-on-windows-10-fixed/

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: (:) [Stop-Computer], UnauthorizedAccessExcepti
on
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Comm
ands.StopComputerCommand

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

Any ideas?

Thanks,
Sean

July 11, 2018 at 4:35 pm

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.

July 13, 2018 at 1:58 pm

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.

Thanks,
Sean

July 13, 2018 at 2:43 pm

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.

July 13, 2018 at 3:54 pm

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}

July 13, 2018 at 3:55 pm

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

-computername (Get-Content names.txt)

July 13, 2018 at 4:01 pm

I probably got the idea from your book 😉