PowerShell script exchange
Post Reply
winnt
Enthusiast
Posts: 29
Liked: 20 times
Joined: Apr 03, 2015 9:19 pm
Full Name: Jason D
Contact:

PowerShell script to alert on disabled jobs

Post by winnt »

I wrote this PowerShell script to e-mail me if any job is disabled. If you want to exclude certain jobs from being alerted on, add key words to the exclusion file such as this:(C:\Scripts\Veeam\NotifyOfDisabledJobs_EXCLUSIONS.IN)

Code: Select all

Backup_FILE01
Backup_FILE47
Replication_FILE
You can call it using a batch file such as this:
(C:\Scripts\Veeam\NotifyOfDisabledJobs.bat)

Code: Select all

powershell.exe c:\scripts\Veeam\NotifyOfDisabledJobs.ps1
I've scheduled this to run every four hours in case I've forgotten to re-enable jobs after a maintenance window.

Code: Select all

<# 
****************************************************************************************
PowerShell script that checks for disabled jobs and sends an e-mail containing the list of disabled jobs

By winnt posted to Veeam forum on May 8, 2022

You will need to install the Veeam Powershell module if you don't run it from the Veeam server

You need to change the e-mail fields to match yours

You need to change the $ScriptDir and $ReportDir variables, or leave them as-is and make 
sure the paths exist for this script file.

Create the file NotifyOfDisabledJobs_EXCLUSIONS.IN and add any job names (or partial names) to exclude.
Here is an example file:
--- NotifyOfDisabledJobs_EXCLUSIONS.IN ---
Backup_Server01
Backup_Server02
Replication_Server0
--------------------------------------------
 
****************************************************************************************
#>

Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

$ScriptDir = 'C:\Scripts\Veeam'

$JobExclusionFilterFile = "$ScriptDir\NotifyOfDisabledJobs_EXCLUSIONS.IN"


$MailTo = "YourName@example.com"
$MailFrom = "YourVeeamBackupServer@example.com" 
$MailSubject = "ALERT: Veeam jobs disabled" 
$SMTPServer = "smtpserver.example.com" 

$DisabledJobs = Get-VBRJob | where {$_.info.IsScheduleEnabled -eq $False }

IF ($DisabledJobs) {

	IF ((Test-Path -Path $JobExclusionFilterFile) -and ((-NOT [string]::IsNullOrWhiteSpace((Get-Content $JobExclusionFilterFile))))) {

		$JobsToExclude = Get-Content "$JobExclusionFilterFile"

		$DisabledJobsWithExclusions = $DisabledJobs.Name | 
			Select-String -Pattern $JobsToExclude -NotMatch 
			
		$DisabledJobsWithExclusions = $DisabledJobsWithExclusions | Out-String

		$JobsToExclude = $JobsToExclude | Out-String
		$FinalReport = $DisabledJobsWithExclusions
		
	} ELSE {

		Write-Host "No job exclusion filter set"

		$JobsToExclude = "None"
		$FinalReport = $DisabledJobs.Name | Out-String
		
	}

	$EmailBody = "Please review the following disabled Veeam jobs and re-enable, re-enable and remove schedule, or add to exceptions list file:

$FinalReport
Jobs with the following search filters are excluded from the report:

$JobsToExclude"

	$EmailBody


	$MailMessage = @{ 
		To = $MailTo
		From = $MailFrom
		Subject = $MailSubject
		Body = $EmailBody
		Smtpserver = $SMTPServer
	} #End_MailMessage

	Send-MailMessage @MailMessage

	
} # EndIf_DisabledJobs
 ELSE {
Write-Host "No disabled jobs"}

HannesK
Product Manager
Posts: 14839
Liked: 3086 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: PowerShell script to alert on disabled jobs

Post by HannesK »

Hello,
thanks for sharing the script with the community.

Best regards,
Hannes

PS: for those who have VeeamONE installed, there is a "Job disabled" alarm that kicks in if a job is disabled for more then 12 hours
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests