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
$username="USERNAME@DOMAIN.COM"
$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 <neil@petersenit.co.uk>' -From Backup.Alerts@DOMAIN.COM -subject "Azure Backup Report" -BodyAsHTML $Body -UseSsl -Port 587 -SmtpServer outlook.office365.com -Credential $creds


The email report will come through as:







param(

    [Parameter(Mandatory=$true)]
    [string]$Path,
    [Parameter(Mandatory=$true)]
    [string]$password
    )

    # 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"   
   
<#
.SYNOPSIS
Stores a password in a file on the local computer for retrevial by scripts.

.DESCRIPTION
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.

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

.PARAMETER Password
Plain text version of password.

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

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

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




Comments