Veeam PowerShell: How to schedule an inventory of a drive and mark the media as free

Since version 7 of Veeam Backup and Recovery I’ve started to use the new capability of backup to tape from within Veeam for offsite storage, rather than continue using Symantec Backup Exec to backup to tape.

Typically I’ll have a backup to disk job that runs a reverse incremental backup, and then I will use a backup to tape job to backup the Veeam configuration and vbk and vbm files from the Veeam repository, so that on each tape we have a full backup.

The downside to this is that you have to mark the tape media as free so that we can fit a full backup onto the tape, if this doesn’t happen the the Veeam backup wil go onto more than one tape and it makes managing the backups a bit more complex, espcially when end users are responsible for swapping the tapes over.

Below is a script that I’ve put together to run an inventory of the tape drive, and then mark the tape as free so that its full capacity can be used for backups. This assumes that you use a manual tape rotation, typically a Grandfather, Father, Son scheme.

Write-host “Prepare Tape for Veeam backup”
Add-PSSnapin -Name VeeamPSSnapin
Get-VBRTapedrive | Start-VBRTapeInventory
Get-VBRTapeMedium -Online | Erase-VBRTapeMedium -confirm:$false

Save the scripts as a ps1 file, and then use Task Scheduler to run it prior to the tape job starting.


After further testing I’ve replace the last two lines of the original script:
$tape = Get-VBRTapeMedium -Online
Move-VBRTapeMedium -Medium $tape -MediaPool Free -Confirm:$false

Get-VBRTapeMedium -Online | Erase-VBRTapeMedium -confirm:$false

Although moving the tape to the Free Media Pool, should allow the data to be overwritten I was finding backup jobs needing two tapes as it wasn’t overwriting the tape. By changing the last line to Erase-VBRTapeMedium the job runs a quick erase and leaves the tape in the current Media Pool.

Useful Links:

1. Veeam PowerShell Guide

2. Veeam PowerShell Forum

Related Posts:

1. Veeam Backup and Replication 7 – Patch 4 released

2. How to change the vPower NFS path in Veeam 7

3. How to view historic backup logs in Veeam 7

4. Veeam file level restore error – No disks have been mounted

5. ESXi 5.1 – VMware Tools – [warning] [vmusr:vmusr] Error in the RPC receive loop: RpcIn: Unable to Send.

9 thoughts on “Veeam PowerShell: How to schedule an inventory of a drive and mark the media as free

  1. J

    Cool tip but one question. How do I find/install just the VeeamPSSnapin on a non Veeam server? Is the only way to download the entire installer and just do a custom install w/ snapin only?

  2. webmastir

    How do you just install the VeeamPSSnapin (on a non Veeam server)? Is the only way to download the entire installer and only install the snapin?

  3. Sam

    For those interested, to perform a full erase (zero-fill) without prompting for confirmation use:

    Erase-VBRTapeMedium -Medium $tape -Long:$true -Confirm:$false

    Hope that helps someone (:

  4. Jens Pfau

    The Script doesn´t work with Veeam 8. The Powershell Parameters has changed.

    This ist my tested Script on Veeam 8:

    Write-host “Prepare Tape for Veeam backup”
    Add-PSSnapin -Name VeeamPSSnapin
    $LibraryName = “QUANTUM ULTRIUM 5”
    $Library = GET-VBRTapeLibrary -Name $LibraryName
    Start-VBRTapeInventory -Library $Library
    Start-Sleep -s 10
    Get-VBRTapeMedium -Drive $Library.Drives | Erase-VBRTapeMedium -confirm:$false

    Without the Sleep Veeam will erase the Tape before Inventory.

Comments are closed.