Powershell Workflow to reboot computers

0

Code:

workflow Test-RemoteReboot{
    param ([string[]]$serverNames)
    foreach -parallel($server in $serverNames){
        Restart-Computer -PSComputerName $server -Wait -Force
    }
}

Test-RemoteReboot SP,SP2

Issue: this is a small excerpt from a pretty long workflow I built in powershell. By all accounts, this should work but I get the following error (even when running this script in isolation):

Microsoft.PowerShell.Utility\Write-Error : The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The computer SP2 is skipped. Fail to retrieve its LastBootUpTime via the WMI service with the following error message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA). At line:433 char:25 + ... Receive-Job -Job $job -Wait -Verbose -Debug -ErrorAction ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], ActionPreferenceStopException + FullyQualifiedErrorId : System.Management.Automation.ActionPreferenceStopException,Microsoft.PowerShell.Commands.WriteErrorCommand + PSComputerName : [localhost]

I looked into the RPC server unavailable issue. Firewall is down, RPC Service is running, Servers are on domain, Workflow running from domain member computer, as domain admin. I can successfully PSRemote into the machines and do whatever. I can even do this:

workflow Test-LocalRebootRemotely{
param ([string[]]$serverNames)
    foreach -parallel($server in $serverNames){
        InlineScript { Restart-Computer -Force } -PSComputerName $server
    }
}

Test-LocalRebootRemotely SP,SP2

The problem is, is that I need a return value to determine if I need to reboot and handle other logic outside of the remote computer. I do notice that there is an abnormal pause just before it errors. So maybe it is a timeout? anyone have a similar issue?

powershell

1 Answer

1

You can try the Restart-Computer cmdlet with the -Protocol WSMan parameter instead of the default DCOM over RPC protocol (-Protocol DCOM).

This would confirm that your RPC network packets are blocked somewhere.

answered on Stack Overflow Nov 8, 2017 by Luke

User contributions licensed under CC BY-SA 3.0