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.
This topic is 1 year and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: 103
Last visit: Thu Mar 07, 2024 2:00 pm

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 1 year and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked