Last Good Backup

PowerShell script exchange

Last Good Backup

Veeam Logoby sidavid » Thu Sep 26, 2013 11:10 am

Hi,

I'm writing a script to know on a certain date, which backup jobs have no run something like :

Code: Select all
$jobName = "TECH"
$date1 = Get-Date -Month 9 -Day 20 -year 2013
Get-VBRJob | ?{$_.Name.StartsWith($jobName) -and ($_.FindLastSession().EndTime.ToShortDateString() -lt $date1.ToShortDateString())} | Select Name


Is this command return me all the backup jobs that have run before 2013/09/20?

I want to know if FindLastSession().EndTime.ToShortDateString() parameter is the good way?

Thanks in advance
sidavid
Enthusiast
 
Posts: 60
Liked: never
Joined: Sun Jan 01, 2006 1:01 am

Re: Last Good Backup

Veeam Logoby v.Eremin » Thu Sep 26, 2013 1:30 pm

Is this command return me all the backup jobs that have run before 2013/09/20?

Nope, you’ve actually tied the script to the jobs which names start with “Tech”. If you want to list every job that had been executed prior to 2013/09/20, you should write something like this:

Code: Select all
$date1 = Get-Date -Month 9 -Day 20 -year 2013
Get-VBRJob | ? {$_.FindLastSession().creationtime -lt $date1} | select name, {$_.FindLastSession().creationtime}


Also, it might be worth adding “auditorial” line that checks whether that the latest job session was successful:

Code: Select all
$date = Get-Date -Month 9 -Day 20 -year 2013
Get-VBRJob | ? {($_.FindLastSession().result -eq "Success") -and ($_.FindLastSession().creationtime -lt $date)} | select name, {$_.FindLastSession().creationtime}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests