Afternoon all,
I've got a script that runs scheduled tasks on some remote computers through Cimsessions.
Start-ScheduledTask -CimSession $CimSessions -TaskName "<Task-Name>"
I then have a timer that runs in a Do/Until
loop until the tasks are completed. However, the loop ends when one server has completed the task even if others have finished. Is there a way I can re-write my loop to continue until all servers have registered that their task is not running
$StartTime = Get-Date
Do{
$ElapsedTime = (Get-Date) - $StartTime
$TotalTime = "{0:HH:mm:ss}" -f ([datetime]$ElapsedTime.Ticks)
$CurrentLine = $host.UI.RawUI.CursorPosition
Write-Output "Running Scheduled Task... [Total Elapsed Time: $(stc $TotalTime yellow)]"
sleep -s 2
$host.UI.RawUI.CursorPosition = $CurrentLine
}Until((Get-ScheduledTask -CimSession $CimSessions -TaskName "<Task-Name").State -ne 'Running')
Note: the line of code $(stc $TotalTime yellow)
is just a custom function that changes the color of the text to yellow