# \[Workflow\] restart-computer

**URL:** <https://forums.powershell.org/t/workflow-restart-computer/3873>\
**Category:** PowerShell Help\
**Created:** [March 12, 2015, 6:44pm UTC](https://forums.powershell.org/t/workflow-restart-computer/3873 "2015-03-12T18:44:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcel-bezemer](https://avatars.discourse-cdn.com/v4/letter/m/f05b48/32.png) [@marcel-bezemer](https://forums.powershell.org/u/marcel-bezemer)\
**Post date:** [March 12, 2015, 6:44pm UTC](https://forums.powershell.org/t/workflow-restart-computer/3873/1 "2015-03-12T18:44:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [March 13, 2015, 12:30am UTC](https://forums.powershell.org/t/workflow-restart-computer/3873/2 "2015-03-13T00:30:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/workflow-restart-computer/3873/3 "2024-05-16T20:45:39Z")

</div>

Closed on May 16, 2024, 8:45pm UTC


