Cleanup unused shares in Veeam Backup & Replication

In Veeam Backup & Replication adding shares to a NAS Backup Job is a two step process. First you need to add the share to the inventory of Veeam Backup & Replication. After you added the share to VBR you are able to add this share to File Backup Jobs.
I talked to a customer how has many changes in his file service where sometimes every day new shares will be created or deleted. So after a while you can mess up the VBR inventory with lots of unused shares.

I was thinking about to help the customer with a short powershell script. And after some tests in my lab I have now a working script. This script is quite easy. It reads the shares added to VBR inventory and also reads all file backup jobs and extracts the backup objects from this jobs. Then it checks for every share if this share is unsed in any file backup job. If it is not used in any share it removes the share from the VBR inventory.

# Get all in VBR existing shares
$allNasShares = Get-VBRNASServer

# Get all VBR NAS Backup Jobs to get used shares in backup jobs
$nasBackupJobs = get-vbrnasbackupjob

# Get from all jobs the added BackupJobObjects
$VBRNASBackupJobObjectsInExistingJobs = @()
ForEach ($nasBackJob in $nasBackupJobs) {
  $VBRNASBackupJobObjectsInExistingJobs += $nasBackJob.BackupObject

#Check for every share of it used in a job    
ForEach ($NasShare in $allNasShares) {
  if (!($NasShare.Path -in $VBRNASBackupJobObjectsInExistingJobs.Path)) {
    Remove-VBRNASServer -Server $NasShare -Confirm:$false
And voila this is the result of the script. It also creates automatically a log file at C:\ProgramData\nasBackupCleanup.log.

The most current version of the script will be available in my personal Github repository unter

Have fun with this code.

You may also like...

Leave a Reply

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

17 − 11 =