Reputation: 669
I am currently developing a backup manager for Hyper-V using PowerShell.
I ran into problems when starting an export job like this:
$job = (export-vm -name "Windows 10" -path F:\VM_Backup\ -asjob)
Now when querying the progress of the job I realized that two objects are inside my Progress
property:
> $job.progress
ActivityId : 0
ParentActivityId : -1
Activity : Export wird ausgeführt
StatusDescription : Gelöscht
CurrentOperation :
PercentComplete : 1
SecondsRemaining : -1
RecordType : Processing
ActivityId : 0
ParentActivityId : -1
Activity : Export wird ausgeführt
StatusDescription : Gelöscht
CurrentOperation :
PercentComplete : 37
SecondsRemaining : -1
RecordType : Processing
While the second progress update makes real progress (increasing percentage), the first one always stays like above.
I have never seen this behavior before and that really doesn't make any sense to me. How do I (programmatically) select the "right" job?
Upvotes: 1
Views: 105
Reputation: 439767
By design, the .Progress
property collects all progress messages written by the job - it doesn't just reflect the latest status.
The most recently written message is the last one added to the .Progress
collection, so you can use index [-1]
to retrieve it.
$job.Progress[-1]
Note: For Start-Job
-created jobs, you must access the .Progress
property on the (one and only) child job instead: $job.ChildJobs[0].Progress[-1]
- see about_Job_Details
.
Upvotes: 1