PowerShell script exchange
Post Reply
shaun2011
Influencer
Posts: 19
Liked: 1 time
Joined: Nov 12, 2011 11:43 am
Contact:

Get running job start time

Post by shaun2011 »

hi,
what is the variable / commands to get start time of a running/active backup/replica job?

below commands did not work,
Get-VBRJob
job.getlaststate -ne "stopped"
Job.ScheduleOptions.StartDateTime

thanks.
veremin
Product Manager
Posts: 20283
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get running job start time

Post by veremin » 1 person likes this post

The following one-liner should meet your expectations:

Code: Select all

asnp VeeamPSSnapin
Get-VBRJob | ?{$_.GetLastState() -eq "Running"} | Select name, {$_.ScheduleOptions.NextRun}  
Hope this helps.
Thanks.
shaun2011
Influencer
Posts: 19
Liked: 1 time
Joined: Nov 12, 2011 11:43 am
Contact:

Re: Get running job start time

Post by shaun2011 »

nope, i ran this command while the job is running and it displays the next scheduled run time of the job.

PS C:\> Get-VBRJob | ?{$_.GetLastState() -ne "stopped"} | Select name, {$_.ScheduleOptions.NextRun}
Name $_.ScheduleOptions.NextRun
---- --------------------------
REP-SERVER 08/06/2013 08:02:00

what i am trying is to get the start time of a active job (while the job is running and not in stopped state). more like current backup session start time?

thanks.
veremin
Product Manager
Posts: 20283
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get running job start time

Post by veremin » 1 person likes this post

You mean the time when a given job has been started?

Code: Select all

asnp VeeamPSSnapin
Get-VBRJob | ?{$_.GetLastState() –eq "Running"} | Select name, {$_.FindLastSession().creationtime}  
Thanks.
shaun2011
Influencer
Posts: 19
Liked: 1 time
Joined: Nov 12, 2011 11:43 am
Contact:

Re: Get running job start time

Post by shaun2011 »

yes, thanks Vladimir!
on the right track now, aim is to check on jobs that runs for longer than usual ...
veremin
Product Manager
Posts: 20283
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get running job start time

Post by veremin » 1 person likes this post

aim is to check on jobs that runs for longer than usual
Ok. Then, it might be worth using the following examples.

This one will output all active jobs that have been running more than 2 hours (this is modifiable parameter; just replace 2 with whatever number you’re willing to):

Code: Select all

asnp VeeamPSSnapin
Get-VBRJob | ?{($_.GetLastState() -eq "Running") -and (((Get-Date) - $_.FindLastSession().CreationTime).TotalHours -gt '2')} | Select name, {$_.FindLastSession().creationtime} 
This one will stop all the active jobs that have been running more than 2 hours (this is modifiable parameter; just replace 2 with whatever number you’re willing to):

Code: Select all

asnp VeeamPSSnapin
Get-VBRJob | ?{($_.GetLastState() -eq "Running") -and (((Get-Date) - $_.FindLastSession().CreationTime).TotalHours -gt '2')} | Stop-VBRJob
Thanks.
veremin
Product Manager
Posts: 20283
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get running job start time

Post by veremin » 4 people like this post

Additionally, have you ever considered implementing Veeam ONE as the solution for tracking your Virtual, as well as Backup, infrastructure. Among others interesting features, there is a predefined alarm that tracks job duration.

Thanks.
shaun2011
Influencer
Posts: 19
Liked: 1 time
Joined: Nov 12, 2011 11:43 am
Contact:

Re: Get running job start time

Post by shaun2011 »

i did not know VeeamOne can track job duration.
thanks for your help ...
veremin
Product Manager
Posts: 20283
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Get running job start time

Post by veremin » 1 person likes this post

You’re welcome. If any additional questions arise, don’t hesitate to let me know. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests