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

Last Good Backup

Post by sidavid »

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
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Last Good Backup

Post by veremin »

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

Who is online

Users browsing this forum: No registered users and 24 guests