PowerShell Progress Monitoring

Is there a way for PowerShell to report progress or fire events before it completes? I just started playing with background tasks in PowerShell, and I wonder how far I can advance this feature.

+4
source share
2 answers

The standard β€œmanual” method is to use the Get-Job cmdlet. As for events, when you create a job using Start-Job, the returned Job object has a "StateChanged" event that you can subscribe to, for example:

$job = Start-Job { Get-Process; Start-Sleep -seconds 60 } Register-ObjectEvent $job -EventName StateChanged ` -SourceIdentifier JobStateChanged ` -Action { Write-Host "Job $($Sender.Id) $($Sender.JobStateInfo)" } 
+10
source

You can also create your own events from a local or remote task and act on them in a local session.

+2
source

All Articles