Hi,
I have a script I put together to update multiple servers at the same time, however some get stuck on the " Invoke-Command -Session $session {Wait-Process powershell}" bit and to find out which server is holding up the batch we have to login to each server and see if a powershell.exe is running then terminate it if its failed, I tried to edit it by putting another write-output after, however of course it is running -parallel so it waits for powershell.exe process to self terminate on all servers.
Anyone know a better way of handling this, would be great if it just ran the all at same time, end to end, and not wait for any in the batch, but again at a bit of a loss on that one.
I’ve removed alot of the script as not relevant
workflow update-servers
{
Param
(
$updateset
)
foreach -parallel -throttlelimit 10 ($vm in $vms)
{
sequence
{
if(Test-Connection $vm.DNSHostname -Count 1 -Quiet)
{
Write-Output "output"
Write-Output "output" | Out-File $log -Append
if(Test-WSMan $vm.DNSHostname -ErrorAction SilentlyContinue)
{
write-output "output"
Write-Output "output" | Out-File $log -Append
inlinescript {
$session = New-PSSession -ComputerName $using:vm.dnshostname
Invoke-Command -Session $session {Stop-Process -Name powershell -Force -ErrorAction SilentlyContinue}
}
InlineScript {
Import-Module PSWindowsUpdate
Invoke-WUInstall -ComputerName $using:vm.DNSHostname -Script {ipmo PSWindowsUpdate; Get-WUInstall -AcceptAll -IgnoreReboot | Out-File C:\temp\Update.log} -Confirm:$false
$session = New-PSSession -ComputerName $using:vm.dnshostname
Invoke-Command -Session $session {Wait-Process powershell}
Write-Output "output"
Write-Output "output" | Out-File $log -Append
}
Checkpoint-Workflow
}