PowerShell script exchange
Post Reply
sidavid
Enthusiast
Posts: 63
Liked: 1 time
Joined: Jan 01, 2006 1:01 am
Contact:

Duration Job

Post by sidavid »

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
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Duration Job

Post by Sethbartlett »

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.
sidavid
Enthusiast
Posts: 63
Liked: 1 time
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Duration Job

Post by sidavid »

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
}
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Duration Job

Post by Sethbartlett »

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.
sidavid
Enthusiast
Posts: 63
Liked: 1 time
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Duration Job

Post by sidavid »

This is what I get:

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

I do not get the duration, thanks
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Duration Job

Post by Sethbartlett »

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.
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Duration Job

Post by tsightler »

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
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Duration Job

Post by Sethbartlett »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests