Skip to main content

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."

 

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


@JonahMay ​@mkevenaar 


@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 


@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.  


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


@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."

 


@damien commenge 

Perfect

🖖💥

Well done Mate!! Thank you kindly!! 


Comment