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