Azure - Recovery Services Vault - Backup Report

You can use the below script to generate a daily email report of backup jobs from you Recovery Services Vault.

Please amend the highlighted areas for your own detials, also consider using New-StoredCredential.ps1 detailed below to store credentials.

Set-ExecutionPolicy Unrestricted -Scope Process -Force
Import-Module Az.RecoveryServices -Force

#Set Variables
$password=ConvertTo-SecureString "Password"-AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ($username, $password)

#Connect to Azure

Connect-AzAccount -Credential $creds
Set-AzContext -SubscriptionId xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

#Email Daily Backup Report

$Body=foreach ($RSV in Get-AzRecoveryServicesvault) {
Get-AzRecoveryServicesBackupJob -VaultID $RSV.ID -Operation "Backup" -From ((Get-Date).AddDays(-1).ToUniversalTime()) |
Select-Object WorkloadName,Operation,Status,StartTime,EndTime,Duration

$Body= "
<h1>Daily Azure Backup Report: " + (Get-AzSubscription).Name +"</h1>
<code>" + ($Body | ConvertTo-HTML)+"</code>"

Send-MailMessage -To 'Neil Petersen <>' -From Backup.Alerts@DOMAIN.COM -subject "Azure Backup Report" -BodyAsHTML $Body -UseSsl -Port 587 -SmtpServer -Credential $creds

The email report will come through as:



    # Convert the password to a secure string
    $SecurePassword = $password | ConvertTo-SecureString -AsPlainText -Force
    # Store the credential in the path
    $SecurePassword | ConvertFrom-SecureString | Out-File $Path
    # Write What we did
    Write-Host "Wrote password to $path"   
Stores a password in a file on the local computer for retrevial by scripts.

Used for securely storing a password on a machine for use with automated scripts.

Takes a password and encrypts it using the local account, then stores that password in a file you specify.
Only the account that creates the output file can decrypt the password stored in the file.

Path and file name for the password file that will be created.

Plain text version of password.

File Specified in Path variable will contain an encrypted version of the password.

.\New-StoredCredential.ps1 -Path c:\scripts\O365Account.txt -Password "Password123"

Puts the encrypted version of Password123 into the c:\scripts\O365Account.txt file