locked
Workflow Restart-Computer -Wait hangs at "Waiting for Windows PowerShell connectivity..." RRS feed

  • Question

  • Hi, 

    I'm writing a script which will include one or more reboots of remote servers. 

    For this I'm using a parallel workflow and the Restart-Computer cmdlet with the -Wait (and also -Force) parameter. I have the console session to the server open, so I follow the reboot procedure, which works. The job just never resumes when the server comes back up. Instead it hangs on this step: 

    "Waiting for Windows PowerShell connectivity..."

    If I cancel out, I can immediately run it again without issue, and it will proceed to reboot the servers and then hang at the same step again. Since these are workgroup servers right now, I also pass pscredentials. 

    Have you seen this behavior before? Any idea what I am missing?

    I based the workflow on the simple example given by the Scripting Guys blog. 

    $ComputerNames = 'IP1','IP2','IP3','IP4'
    $Credential = (Get-Credential)
    workflow Test-Restart {
        param (
            [string[]]$ComputerNames,
            [pscredential]$Credential
        )

        foreach -parallel ($Computer in $ComputerNames) {
            Get-WmiObject -Class Win32_ComputerSystem -PSComputerName $Computer -PSCredential $Credential
            Restart-Computer -Wait -Force -PSComputerName $Computer -PSCredential $Credential
            Get-WmiObject -Class Win32_ComputerSystem -PSComputerName $Computer -PSCredential $Credential
        }
    }
    Test-Restart -ComputerNames $ComputerNames -Credential $Credential



    Andreas Hultgren<br/> MCTS, MCITP<br/> <a href="http://ahultgren.blogspot.com/">http://ahultgren.blogspot.com/</a>

    Tuesday, August 29, 2017 9:22 AM

Answers

  • It looks like the WSMan trustedhosts list was the issue. As a test I ran the below commands on one of the target servers and then on the server I'm running the script from. 

    Set-Item WSMan:\localhost\Client\TrustedHosts *
    Restart-Service WinRM

    Now it resumes the job as expected. 

    Edit: 

    It looks like it's enough to run the commands on the server you run the script from. After I did, all the servers are now resuming the workflow. 


    Andreas Hultgren<br/> MCTS, MCITP<br/> <a href="http://ahultgren.blogspot.com/">http://ahultgren.blogspot.com/</a>


    • Marked as answer by A.Hultgren Tuesday, August 29, 2017 9:51 AM
    • Edited by A.Hultgren Tuesday, August 29, 2017 9:57 AM
    Tuesday, August 29, 2017 9:51 AM