[Workflow] restart-computer

Welcome Forums General PowerShell Q&A [Workflow] restart-computer

This topic contains 1 reply, has 2 voices, and was last updated by

4 years, 2 months ago.

  • Author
  • #23299

    Topics: 1
    Replies: 1
    Points: 0
    Rank: Member

    Hey all,

    I seem to have run into some peculiar things with my workflow which I can't seem to pinpoint :S

    I have this workflow I am toying around with, to reboot a whole list of servers parallel. We use a function to retrieve a bunch of servers with all sorts of properties from a cmdb. I then want to reboot my resulted servers if they don't have a property " restart:"N". Nothing too fancy here ..
    Problem is when I run this workflow I get different computers every time where powershell has problems "verifying the computer has been restarted.... " .

    So here is the code:

    workflow Reboot-Server
    [Parameter(Mandatory = $true)]

    [Parameter(Mandatory = $false)]
    [int32]$ThrottleLimit =25,

    [Parameter(Mandatory = $false)]

    [Parameter(Mandatory = $false)]
    [int]$Timeout = 240

    foreach -parallel -throttlelimit $throttleLimit ($server in $Serverlist)
    if ($server.Restart -ne 'N')
    if (Test-Connection -Count 1 -ComputerName $($server.fqdn) -ErrorAction SilentlyContinue -Verbose)
    Write-Verbose -Message "Rebooting $($server.fqdn)"
    Restart-Computer -PSComputerName $($server.fqdn) -Timeout $Timeout -Delay 10 -Wait -PSCredential $credentials -Force
    Write-Warning -Message "Failed To reboot $($server.fqdn)"
    Write-Warning -Message "$($server.fqdn) Not online!"

    When I run this workflow 10+ times it's different computers with problems :S
    Microsoft.PowerShell.Management\Restart-Computer : Failed to restart the computer with the following error message: The computer did not finish restarting within the specified time-out period..

    I tried for -For WMI, -For Winrm and default Powershell but same weird unreliable results.

    Second thing is, when I do a measure command of my workflow it runs for 900+ seconds. Which I find weird when I specify a timeout of 240 seconds :S

  • #23304

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Yeah, that -Wait thing, for me, has always been super-dicey. I'd consider writing your own restart routine, frankly, that re-checks the computer every 10 seconds or something.

    And your timeout is probably under a threshold. Frankly, Workflow isn't meant to be "quick" it's meant to be "eventually." If you're wanting a timeout, you probably shouldn't be using Workflow.

The topic ‘[Workflow] restart-computer’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort