Backup Exec 2014 digest powershell script.

I was tired of getting close to 100 backup status reports each day, so I wrote a quick digest script and disabled notifications on all my jobs. I'm not very good with Powershell, so it's pretty ugly, but it works, and I get a nice quick digest that tells me if I have anything to really address.

Hopefully this helps someone who is struggling under the weight of backup reporting.

STUFF -

1. This script only cares about errors, cancellations, successes and exceptions. If you want more things, just add more tables.

2. Only verified on Powershell 3.0

3. I run this as a system task on a daily basis on my BE server.

4. YMMV, but they are just GET cmdlets, you aren't doing anything but gathering data and emailing it.

Credit - "sendemailstatus" is a function I picked up from -Mark- on technet because I like the emails it sends.

---------------------------------------------------------------------------------------------------------------------------------------------------------------

#Email report of error jobs sorted by Time ended

#Importing Backup Exec Powershell awesomeness
import-module bemcli

#last 24 hours
$lastday = (Get-Date).adddays(-1)

###########Lets make some variables##################################
$SmtpServer = 'your.mail.server'
$From = 'BES@domain.com'
$To = 'Your_Email'
$Subject = 'Backup Exec Job digest'
###########Thats enough variables####################################

Function SendEmailStatus($From, $To, $Subject, $SmtpServer, $BodyAsHtml, $Body)
{	$SmtpMessage = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body
	$SmtpMessage.IsBodyHTML = $BodyAsHtml
	$SmtpClient = New-Object System.Net.Mail.SmtpClient $SmtpServer
	$SmtpClient.Send($SmtpMessage)
	$SmtpMessage.Dispose()
}

$Style = "<Style>BODY{font-size:12px;font-family:verdana,sans-serif;color:black;font-weight:normal;}" + `
"TABLE{width:100%;border-width:1px;cellpadding:0;cellspacing:0;border-style:solid;border-color:black;border-collapse:collapse;}" + `
"TH{background:#d3d3d3;font-size:12px;border-width:1px;padding:10px;border-style:solid;border-color:black;}" + `
"TR{font-size:12px;border-width:1px;padding:10px;border-style:solid;border-color:black;}" + `
"TD{width:15%;font-size:10px;border-width:1px;padding:4px;border-style:solid;border-color:black;}</Style>"

$Table1 = get-bejob | Get-BEJobHistory -FromStartTime $lastday -jobstatus Error | sort Name | select Name,JobType,JobStatus,@{name='Size (GB)';expression={$_.TotalDataSizebytes/1073741824}},ErrorMessage | Convertto-html -fragment
$Table2 = get-bejob | Get-BEJobHistory -FromStartTime $lastday -jobstatus Canceled | sort Name | select Name,JobType,JobStatus,@{name='Size (GB)';expression={$_.TotalDataSizebytes/1073741824}},ErrorMessage | Convertto-html -fragment
$Table3 = get-bejob -jobtype backup | Get-BEJobHistory -FromStartTime $lastday -jobstatus Succeeded | sort Name | select Name,JobType,JobStatus,@{name='Size (GB)';expression={$_.TotalDataSizebytes/1073741824 -as 'Int'}} | Convertto-html -fragment
$Table4 = get-bejob -jobtype backup | Get-BEJobHistory -FromStartTime $lastday -jobstatus SucceededWithExceptions | sort Name | select Name,JobType,JobStatus,@{name='Size (GB)';expression={$_.TotalDataSizebytes/1073741824 -as 'Int'}} | Convertto-html -fragment

$TablesHead = "<html><head>$Style</head>"
$TablesBody = "<body><table><TR><TD align=center bgcolor=RED><font color=WHITE><B>JOBS WITH ERRORS</B></font></TD></TR></table>$Table1$Table2 `n<table><TR><TD align=center bgcolor=Green><font color=WHITE><B>SUCCESSES</B></font></TD></TR></table>$Table3<table><TR><TD align=center bgcolor=Orange><font color=WHITE><B>SUCCESSES WITH EXCEPTIONS</B></font></TD></TR></table>$Table4</body>"
$TablesFoot = "</html>"
$email = $TablesHead + $TablesBody + $TablesFoot

SendEmailStatus -From $From -To $To -Subject $Subject -SmtpServer $SmtpServer -BodyAsHtml $True -Body ($email)

 

-------------------------------------------------------------------------------------------------------

Cheers.

1 Reply
Highlighted

...this is simply too good to

...this is simply too good to be placed as a forum query. It's going to get lost.

Please repost this as a new blog on the link below!

https://www-secure.symantec.com/connect/blogs/discover

Thanks!