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