[PowerShell, PowerCLI] Check for VMs that are not being backuped

  • 4 November 2020
  • 5 comments
  • 469 views

Userlevel 7
Badge +5
  • Veeam Legend, Veeam Vanguard
  • 550 comments

If you do not run VeeamONE, it can be challenging to check if every VM that should be backed up, is really backed up. Therefore I wrote a small PowerShell script. 

Basically this script looks for each VM if there is a restore point for this VM. If not, it gets listed. 

Extra feature: 

  • Script connects to every vCenter that is registered in B&R server.
  • There is a Blocklist included: when VMs should not be backuped, just place their name in the blocklist and they will not be shown in the list. So you can exclude VMs without editing the script.

Notes:

  • CredObject.xml is used for stored, encrypted credentials.
  • Script connects to local B&R server, so it should run there if not changed.

 

# Load Plugin and module
Add-PSSnapin VeeamPSSnapin
Import-Module VMware.VimAutomation.Core

# Configure for multiple vCenter Connections
Set-PowerCLIConfiguration -DefaultVIServerMode Multiple -Scope Session -Confirm:$false
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false

# Connect to local B&R Server
Connect-VBRServer -Server localhost

# Read Credential-File
$WorkingDir = "C:\_install\script\"
$CredObject = Import-Clixml -Path ($WorkingDir + "CredObject.xml")

# Connect to vCenter servers, added to B&R server
Get-VBRServer -Type VC | ForEach-Object {
Connect-VIServer $_.name -Credential $CredObject -ErrorAction Continue
}

# Read VMs in blocklist
$Blocklist = Get-Content -path ($WorkingDir + "Blocklist.txt") -ErrorAction SilentlyContinue | Foreach {$_.TrimEnd()}

# Read all VMs
$VMs = Get-VM | select Name, MemoryGB, PowerState, VMHost, Folder

# Query Veeam Restore Points
$result = @()
$VbrRestore = Get-VBRBackup | Where-Object {$_.jobtype -eq "Backup"} | ForEach-Object {$Jobname = $_.jobname; Write-Output $_;} | Get-VBRRestorePoint | Select-Object vmname, @{n="Jobname"; e={$Jobname}} |Group-Object vmname
$VbrRestore = $VbrRestore | ForEach-Object {$_.Group | Select-Object -first 1}

# Check, if VM on blocklist and a restore point exists
$VMs | ForEach-Object {
if (($_.name -notin $Blocklist) -and ($_.name -notin $VbrRestore.vmname)) {
$result += $_
}
}
$result | ft -AutoSize

# Close connections
Disconnect-VIServer * -Confirm:$false
Disconnect-VBRServer

 


5 comments

Userlevel 2

Thank you, very usefull script.

Tested and found 2 VMs without backups ;-)

 

Userlevel 7
Badge +5

Thank you, very usefull script.

Tested and found 2 VMs without backups ;-)

 

So sharing the script has already paid off!

:thumbsup:

Userlevel 6
Badge +2

Excellent resource. Thanks a lot. 

Will it be still valid for future releases or you need to do some housekeeping stuff?

Userlevel 7
Badge +5

Excellent resource. Thanks a lot. 

Will it be still valid for future releases or you need to do some housekeeping stuff?

Thanks!

Good question. The beauty when using PowerShell is the compatibility. This Script will work in v9, v10 and v11 as well. 

 

really very usable!
Thank you

Comment