Knowledge Base Article

Backup Exec 2014 digest powershell script.

Backup Exec 2014 digest powershell script.

Cutting down notification clutter

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 onder the weight of backup reporting get out from under the weight.

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

Published 10 years ago
Version 1.0

Was this article helpful?

2 Comments

  • Your script is absolutely beutiful. Thank you for posting!

    I had some issues running it, so I made a few adjustments.

    - Added module verification (the module loads in my profile so I do get nasty errors otherwise)
    - Added SMTP Authentication (Not mandatory)
    - Added SMTP settings (Port and SSL)

    #Email report of error jobs sorted by Time ended
    
    #Importing Backup Exec Powershell awesomeness
    $Module = Get-Module bemcli
    
    If(!$Module){
        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'
    
    #Authentication# - Not mandatory
    $Username = ''
    $Password = ''
    
    #Settings#
    $SSL = $false
    $Port = '25'
    ###########Thats enough variables####################################
    
    Function SendEmailStatus($From, $To, $Subject, $SmtpServer, $Username, $Password, $BodyAsHtml, $Body)
    {	$SmtpMessage = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body
    	$SmtpMessage.IsBodyHTML = $BodyAsHtml
    	$SmtpClient = New-Object System.Net.Mail.SmtpClient($SmtpServer, $Port)
        
        If($SSL){
            $SmtpClient.EnableSSL = $true
        }
    
        If($Username -and $Password){
            $SmtpClient.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)
        }
    
    	$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 -Username $Username -Password $Password -BodyAsHtml $True -Body ($email)

     

  • Thanks so much for this! This is so handy, it's saving me tons of time with the daily checks and reporting!

     

    Owen