Backup Software

PowerShell Compare VM inventory with Veeam Backup Jobs

Let's see how we can use PowerShell Compare VM inventory with Veeam Backup Jobs to audit backup jobs to make sure we are backing up all critical VMs

If you run Veeam Backup & Replication in your environment and you have many VMs in your VMware vSphere inventory and you want to audit to make sure you have corresponding Veeam Backup jobs in place for those VMs, we can with PowerShell compare VM inventory with Veeam Backup Jobs. Let’s take a quick look at how with a few one line commands we can effectively compare our inventory with our backup jobs.

veeamcomp01

PowerShell Compare VM inventory with Veeam Backup Jobs

The script assumes your Veeam backup job names match the virtual machine inventory names. ย Let’s look at this quick script a few lines at a time. ย The first thing the script does is check connections to both vCenter as well as your Veeam Backup & Replication server.

#Connect vCenter

If ($Cred -eq $null)
{
$cred = get-credential
}
If ($vcenter -eq $null){
$vcenter = Read-Host  -Prompt 'Enter vCenter Server Name'
}
$vi = connect-viserver $vcenter -credential $cred

#Connect to Veeam

If ($vbrserver -eq $null){
$vbrserver = Read-Host  -Prompt 'Enter Veeam Server name'
} 
Connect-VBRServer -server $vbrserver

Next, we simply run the compare using a few one liners with both the Veeam PowerShell commandlets as well as PowerCLI commands to pull cluster information and VM information.

Breakdown – The first line ($backupjobs) gets our Veeam Backup & Replication backup jobs. ย The ($prodvms) line as the name implies, gets the production VM names by querying the cluster and piping that into theย get-vm command. ย Theย ($differencevms) variable compares the two previous variables and then sends the differences to a text file

#Compare VMs in Inventory to Backup Jobs

$backupjobs = get-vbrjob | where-object {$_.JobTargetType -eq "Backup"} | select -expandproperty Name
$prodvms = get-cluster | where-object {$_.Name -match "cluster1|cluster2"} | get-vm | sort-object | select -expandproperty Name
$differencevms = $prodvms | where {$backupjobs -notcontains $_} | sort-object | out-file c:testprodvmsdiff.txt

Thoughts

The PowerShell integration with Veeam proves to be extremely powerful once again as we can replace very manual and tedious processes with quick automated ones. ย Running a quick compare of Veeam jobs compared to VMware inventory can prove very useful for auditing to quickly identify virtual machines that may have been inadvertently left out of backup job creation. ย Feel free to contribute to the project on Git here to make it better!

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.