[Workflow] restart-computer

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 8 months ago.

  • Author
    Posts
  • #23299
    Profile photo of Marcel Bezemer
    Marcel Bezemer
    Participant

    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
    {
    param(
    [Parameter(Mandatory = $true)]
    [ValidateNotNull()]
    $Serverlist,

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

    [Parameter(Mandatory = $false)]
    [PSCredential]$credentials,

    [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)
    {
    try
    {
    Write-Verbose -Message "Rebooting $($server.fqdn)"
    Restart-Computer -PSComputerName $($server.fqdn) -Timeout $Timeout -Delay 10 -Wait -PSCredential $credentials -Force
    }
    Catch
    {
    Write-Warning -Message "Failed To reboot $($server.fqdn)"
    }
    }
    else
    {
    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
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

You must be logged in to reply to this topic.