<# .SYNOPSIS This script will connect to Symantec BackupExec server and using PowerShell, it will return information about the backup jobs: -Name -Period .NOTES Author : Pedro Simões .LINK http://blog.mirandasimoes.eu .PARAMETER Name Name of the Job .PARAMETER Period Number of Days Until Critical .EXAMPLE .\check_backupexec_jobs.ps1 -Name "BACKUP IT Machines-Full" -Period 10 # if it passes more than 10 days the it will return critical and if job Status Fails will Return Critical .EXAMPLE .\check_backupexec_jobs.ps1 -Name "BACKUP IT Machines-Full" #if no Period indicated will return last recorded date but doesn't return critical unless job status Fails #> #region parameters Param( [string]$Name, [int]$Period ) #endregion parameters $name = $Name -replace "`n","" -replace "\""","" # Fix for NCPA $period=$Period # Symantec Backup Exec 2012 job status check Import-Module BEMCLI $job = Get-BEJob -Name $name if ($job -eq $null) { $name = "'" + $name + "'" Write-Host "UNKNOWN! No such a job: $name." exit 3 } Try { if ( $Period > 0 ) { $job = Get-BEJobHistory -Name $name -FromStartTime (Get-Date).AddDays(-($Period)) |Select * } Else { $job = Get-BEJob $Name |Get-BEJobHistory |select -last 1 } } Catch { Write-Error $_.Exception.Message exit 3 } if ($job.JobStatus -eq "Error") { $name = "'" + $name + "'" Write-Host "CRITICAL! Errors were encountered during the backup process of the following job: $name." exit 2 } if ($job.JobStatus -ne "Succeeded") { $name = "'" + $name + "'" Write-Host "WARNING! Job $name didn't fully succeed. Status: $($job.JobStatus)" exit 1 } if ((Get-Date).AddDays(-$period) -gt (get-date $job.StartTime)) { Write-Host "CRITICAL! Last run of job: $name more than $period days ago. Last Run: $($job.StartTime)" exit 2 } else { Write-Host "OK! Backup process of job $name completed successfully. Last Run: $($job.StartTime)" exit 0 }