Duration Job

PowerShell script exchange

Duration Job

Veeam Logoby sidavid » Thu Jul 05, 2012 12:34 am

Hi
I try to get the Duration of all my jobs:

This one is working, if I mention one 1 job:
$vbrjobname = "T1 VM1"
$job = Get-VBRJob | ?{$_.Name -eq $vbrjobname}
$session = Get-VBRBackupSession | ?{$_.Name -eq $job.Name}
$Duration = $session.EndTime - $session.CreationTime
$TimeSpan = $Duration
$Duration = '{0:00}:{1:00}:{2:00}' -f $TimeSpan.Hours, $TimeSpan.Minutes, $TimeSpan.Seconds
Write-Host $Duration

This one is not working, if I mention several jobs that start with T1
Get-VBRJob | where {$_.name.StartsWith("T1")} | foreach {
$vbrjobname = "TECH2 PrivateLuc"
$job = Get-VBRJob | ?{$_.Name -eq $vbrjobname}
$session = Get-VBRBackupSession | ?{$_.Name -eq $job.Name}
$Duration = $session.EndTime - $session.CreationTime
$TimeSpan = $Duration
$Duration = '{0:00}:{1:00}:{2:00}' -f $TimeSpan.Hours, $TimeSpan.Minutes, $TimeSpan.Seconds
Write-Host $vbrjobname + $Duration
}
What it is Wrong?
Many thanks for your help
sidavid
Enthusiast
 
Posts: 60
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: Duration Job

Veeam Logoby Sethbartlett » Thu Jul 05, 2012 3:33 pm

Code: Select all
Get-VBRJob | where {$_.name.StartsWith("T1")} | foreach {
$vbrjobname = "TECH2 PrivateLuc"
$job = Get-VBRJob | ?{$_.Name -eq $vbrjobname}


You got a list of jobs that start with T1, but then specified one job specifically $vbrjobname = "TECH2 PrivateLuc"
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Duration Job

Veeam Logoby sidavid » Thu Jul 05, 2012 5:41 pm

Sorry it was during my test, if I run this, it is not working either:

Get-VBRJob | where {$_.name.StartsWith("T1")} | foreach {
$vbrjobname = $_.Name
$job = Get-VBRJob | ?{$_.Name -eq $vbrjobname}
$session = Get-VBRBackupSession | ?{$_.Name -eq $job.Name}
$Duration = $session.EndTime - $session.CreationTime
$TimeSpan = $Duration
$Duration = '{0:00}:{1:00}:{2:00}' -f $TimeSpan.Hours, $TimeSpan.Minutes, $TimeSpan.Seconds
Write-Host $vbrjobname + $Duration
}
sidavid
Enthusiast
 
Posts: 60
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: Duration Job

Veeam Logoby Sethbartlett » Thu Jul 05, 2012 5:48 pm

What data do you get? Is it just blank with the name? When I run that, I get some blank data but I know those jobs haven't ran.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Duration Job

Veeam Logoby sidavid » Thu Jul 05, 2012 10:53 pm

This is what I get:

T1 VM1 + ::
T1 VM2 + ::
T1 VM3 + ::
T1 VM4 + ::

I do not get the duration, thanks
sidavid
Enthusiast
 
Posts: 60
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: Duration Job

Veeam Logoby Sethbartlett » Fri Jul 06, 2012 2:03 pm

Have all these jobs ran? When I run it, it works for me. Just tested it out again.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Duration Job

Veeam Logoby tsightler » Fri Jul 06, 2012 2:59 pm

I think the problem is these commands:
Code: Select all
$session = Get-VBRBackupSession | ?{$_.Name -eq $job.Name}
$Duration = $session.EndTime - $session.CreationTime

The $session variable will be populated with all sessions from the selected job, which is going to make the calculation for $Duration unpredictable at best. I'm assuming you are wanting the most recent session for the job so I'd say something like this is probably more likely to work reliably:

Code: Select all
$session = $job.findlastsession()
$Duration = $session.EndTime - $session.CreationTime
tsightler
Veeam Software
 
Posts: 4775
Liked: 1742 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Duration Job

Veeam Logoby Sethbartlett » Fri Jul 06, 2012 3:08 pm

Oh derp, nice Tom, I completely forgot the Get-VBRBackupSession would give a complete array and it's grabbing no data from the whole array rather than the most recent object. I missed that too :)
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests