Page 1 of 1

Add-JobTracker - how to measure time

Posted: Tue Nov 29, 2022 9:30 am
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?

Re: Add-JobTracker - how to measure time

Posted: Tue Nov 29, 2022 1:22 pm
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

Re: Add-JobTracker - how to measure time

Posted: Tue Nov 29, 2022 11:48 pm
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?

Re: Add-JobTracker - how to measure time

Posted: Wed Nov 30, 2022 12:48 am
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.