Add-JobTracker - how to measure time

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
lontru
Posts: 101
Last visit: Tue Jan 31, 2023 5:14 am

Add-JobTracker - how to measure time

Post by lontru »

I want to measure how long time the job took to finish?

how do i do that when i use the Add-Jobtracker for my functions?
jvierra
Posts: 15360
Last visit: Thu Feb 02, 2023 9:14 am
Answers: 27
Has voted: 4 times
Been upvoted: 31 times

Re: Add-JobTracker - how to measure time

Post by jvierra »

Get the time before you start the job: $starttime = [datetime]::Now

Get the time when job ends: $endtime =[datetime]::Now

Now the elapsed time: $elapsedtime = $endtime - $starttime

This will help you get started with PowerShell and using math with objects.

https://www.sapien.com/books_training/W ... werShell-4
User avatar
lontru
Posts: 101
Last visit: Tue Jan 31, 2023 5:14 am

Re: Add-JobTracker - how to measure time

Post by lontru »

that was also my first attempt but when i got multiple Jobs running I need to know when the last one stopped to get the overall time.

So at each job end have a datetime appended to a array and from that array take the oldest date but when do i know that every think is done?
jvierra
Posts: 15360
Last visit: Thu Feb 02, 2023 9:14 am
Answers: 27
Has voted: 4 times
Been upvoted: 31 times

Re: Add-JobTracker - how to measure time

Post by jvierra »

I recommend starting with the free book I linked. It will teach you the basics of how to test various conditions in a script.

You will need to check the jobs array. When it is empty then all jobs are done.

Note that each job object also has the runtime and job status included in the job object.

https://learn.microsoft.com/en-us/dotne ... lsdk-7.2.0

The job object also contains the job start and end times.
Locked