Don't miss out on new posts! Sign up!
Backup Software

PowerShell Compare VM inventory with Veeam Backup Jobs

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.


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


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!

Don't miss out on new posts! Sign up!

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon 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.

Related Articles

Leave a Reply

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