Skip to main content
Solved

Scripting Help - Removing Offline Tape Backups


We are attempting to script a way to remove offline Tape backups from Veeam so that they can be reused without error.

 

Can someone please help us with the correct cmdlet and syntax to search for all offline tapes and remove them from catalog?

 

I have attached the script we are working with. It searches all media but does not find any offline tapes and it does not error out.

 

# Get all media pools
$mediaPools = Get-VBRTapeMediaPool

foreach ($mediaPool in $mediaPools) {
    Write-Host "Checking media pool: $($mediaPool.Name)"

    # Get all tapes in the media pool
    $tapes = Get-VBRTapeMedium -MediaPool $mediaPool

    foreach ($tape in $tapes) {
        # Check the tape location for "Offline" status
        if ($tape.Location -eq "Offline") {
            Write-Host "Found offline tape: $($tape.Barcode) in media pool: $($mediaPool.Name)"

            try {
                # Attempt to remove offline tape
                Remove-VBRTapeMedium -TapeMedium $tape -Confirm:$false
                Write-Host "Removed offline tape: $($tape.Barcode)"
            } catch {
                Write-Host "Failed to remove tape: $($tape.Barcode). Error: $($_.Exception.Message)"
            }
        }
    }
}

Write-Host "Script execution completed."

 

Best answer by damien commenge

TaylorNetter wrote:
damien commenge wrote:

@TaylorNetter 

Hello,

Are you sûre you want to remove it from veeam database ?

You will need to inventory it again if you want to know what data are in the tape.

Usually if you just want the tape to be able to use without any restriction you just need to put it in free media pool 

Yes, we would like to remove them. We have instances where these tapes sometimes get reused after coming back from our vendor and we just wipe them and reuse them.

We want to make sure they are removed before inventorying them, we have had instances in the past where our current process errors out because the tape wasn't removed prior to inventory.  

OK

I think there are several errors :

$tape.Location -eq "Offline"

$tape.Location return an object and not a property. 

You need to query $tape.Location.type property. Value is none for offline or Slot.

When type = slot you can have the slot number with 

$tape.Location.SlotAddress

$tape.Location.Type -eq "None"

Then the cmdlet Remove-VBRTapeMedium doesn’t have a parameter “TapeMedium” so you need to replace 

Remove-VBRTapeMedium -TapeMedium $tape -Confirm:$false to

 

Remove-VBRTapeMedium -Medium $tape -Confirm:$false

Then , when you use try / catch, you need to have ErrorAction set to Stop . 

You could use a variable to set it for the entire script or just for the cmdlet on the try block.

This should work (work on my lab) :

# Get all media pools
$mediaPools = Get-VBRTapeMediaPool

foreach ($mediaPool in $mediaPools) {
    Write-Host "Checking media pool: $($mediaPool.Name)"

    # Get all tapes in the media pool
    $tapes = Get-VBRTapeMedium -MediaPool $mediaPool

    foreach ($tape in $tapes) {
        # Check the tape location for "Offline" status
        if ($tape.Location.Type -eq "None") {
            Write-Host "Found offline tape: $($tape.Barcode) in media pool: $($mediaPool.Name)"

            try {
                # Attempt to remove offline tape
                Remove-VBRTapeMedium -Medium $tape -Confirm:$false -ErrorAction Stop
                Write-Host "Removed offline tape: $($tape.Barcode)"
            } catch {
                Write-Host "Failed to remove tape: $($tape.Barcode). Error: $($_.Exception.Message)"
            }
        }
    }
}

Write-Host "Script execution completed."

 

View original
Did this topic help you find an answer to your question?

7 comments

Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • 8489 comments
  • January 22, 2025

@Madi.Cristil ​@safiya -- this might get more traction in the Automation Desk section since it concerns scripting.


safiya
Forum|alt.badge.img+6
  • Community Analyst
  • 89 comments
  • January 23, 2025

damien commenge
Forum|alt.badge.img+5

@TaylorNetter 

Hello,

Are you sûre you want to remove it from veeam database ?

You will need to inventory it again if you want to know what data are in the tape.

Usually if you just want the tape to be able to use without any restriction you just need to put it in free media pool 


  • Author
  • Not a newbie anymore
  • 2 comments
  • January 24, 2025
damien commenge wrote:

@TaylorNetter 

Hello,

Are you sûre you want to remove it from veeam database ?

You will need to inventory it again if you want to know what data are in the tape.

Usually if you just want the tape to be able to use without any restriction you just need to put it in free media pool 

Yes, we would like to remove them. We have instances where these tapes sometimes get reused after coming back from our vendor and we just wipe them and reuse them.

We want to make sure they are removed before inventorying them, we have had instances in the past where our current process errors out because the tape wasn't removed prior to inventory.  


MarkBoothman
Forum|alt.badge.img+7
  • Veeam Legend
  • 197 comments
  • January 24, 2025

I would consider posting this query in the forums. There is a PowerShell sub topic for VBR.

https://forums.veeam.com/powershell-f26/

 

HTH

Mark


damien commenge
Forum|alt.badge.img+5
  • Veeam Legend
  • 115 comments
  • Answer
  • January 24, 2025
TaylorNetter wrote:
damien commenge wrote:

@TaylorNetter 

Hello,

Are you sûre you want to remove it from veeam database ?

You will need to inventory it again if you want to know what data are in the tape.

Usually if you just want the tape to be able to use without any restriction you just need to put it in free media pool 

Yes, we would like to remove them. We have instances where these tapes sometimes get reused after coming back from our vendor and we just wipe them and reuse them.

We want to make sure they are removed before inventorying them, we have had instances in the past where our current process errors out because the tape wasn't removed prior to inventory.  

OK

I think there are several errors :

$tape.Location -eq "Offline"

$tape.Location return an object and not a property. 

You need to query $tape.Location.type property. Value is none for offline or Slot.

When type = slot you can have the slot number with 

$tape.Location.SlotAddress

$tape.Location.Type -eq "None"

Then the cmdlet Remove-VBRTapeMedium doesn’t have a parameter “TapeMedium” so you need to replace 

Remove-VBRTapeMedium -TapeMedium $tape -Confirm:$false to

 

Remove-VBRTapeMedium -Medium $tape -Confirm:$false

Then , when you use try / catch, you need to have ErrorAction set to Stop . 

You could use a variable to set it for the entire script or just for the cmdlet on the try block.

This should work (work on my lab) :

# Get all media pools
$mediaPools = Get-VBRTapeMediaPool

foreach ($mediaPool in $mediaPools) {
    Write-Host "Checking media pool: $($mediaPool.Name)"

    # Get all tapes in the media pool
    $tapes = Get-VBRTapeMedium -MediaPool $mediaPool

    foreach ($tape in $tapes) {
        # Check the tape location for "Offline" status
        if ($tape.Location.Type -eq "None") {
            Write-Host "Found offline tape: $($tape.Barcode) in media pool: $($mediaPool.Name)"

            try {
                # Attempt to remove offline tape
                Remove-VBRTapeMedium -Medium $tape -Confirm:$false -ErrorAction Stop
                Write-Host "Removed offline tape: $($tape.Barcode)"
            } catch {
                Write-Host "Failed to remove tape: $($tape.Barcode). Error: $($_.Exception.Message)"
            }
        }
    }
}

Write-Host "Script execution completed."

 


  • Author
  • Not a newbie anymore
  • 2 comments
  • January 24, 2025

@damien commenge 

Perfect

🖖💥

Well done Mate!! Thank you kindly!!