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:\test\prodvmsdiff.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!