Skip to main content
Question

Powershell - Querying library for only tapes currently in slots or drives

  • December 29, 2025
  • 10 comments
  • 32 views

Forum|alt.badge.img+1

I have asked this before, but I’ll ask again:

 

I need to write a report about tapes that currently in my library that are FULL. This command, unfortunately, is monumentally slow:

$TapesToBeEjected = Get-VBRTapeMedium -Library $LibraryName | Where {{$_.IsFull -eq $TRUE}} | Select Name, LastWriteTime, MediaPoolID, IsFull, Location | Sort -Property MediaPoolID, Name

So rather than querying the all the tapes that Veeam has ever used (I have over 1300), I figure it will be faster to just query the library for the tapes *currently* in the slots and drives (that will be about 80). Then I can do the $_.IsFull on just those.

But I am not seeing a command that seems to do that. Is there one, that queries the library and returns tapes in slots and drives?

Otherwise I would have to loop though Get-VBRTapeMedium -Library $LibraryName , select only $_.Location = Slot or Drive, and then re-select for $_.IsFull.
And I don't think that would be materially faster.

Is there a better way to get the info I need?

10 comments

Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • December 29, 2025

Try and see if this works -

Get-VBRTapeMedium | Where-Object { $_.Location.Type -in @("Slot","Drive") -and $_.IsFull -eq $true } | Select-Object Barcode, MediaPool, @{n="Location";e={$_.Location.Type}}

 


Forum|alt.badge.img+1
  • Author
  • Comes here often
  • December 29, 2025

That is a whole lot better in terms of spped!

 

VERBOSE:
VERBOSE: Script Starting: 12/29/2025 14:40:44
VERBOSE: Library: QUANTUM Scalar i3-i6 282G
VERBOSE: TapesToBeEjected.Count = 12
VERBOSE:
VERBOSE: Script Ending: 12/29/2025 14:44:04
VERBOSE:
VERBOSE: Script run time: 00:03:20.2816283

However, this says 12 tapes, my other report shows 14 (and still running ...).


Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • December 29, 2025

Not sure where the differences is between them as this does both slots and drives where tapes are full.  You may need to wait on the other script to finish then compare them to see where the difference is.


Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • December 29, 2025

Also since your script line shows the Library being queried try this code -

$lib = Get-VBRTapeLibrary -Name "YourLibraryName"

Get-VBRTapeMedium |
Where-Object {
$_.LibraryId -eq $lib.Id -and
$_.Location.Type -in @("Slot","Drive") -and
$_.IsFull -eq $true
} |
Select Barcode, MediaPool, Location

 


Forum|alt.badge.img+1
  • Author
  • Comes here often
  • December 29, 2025

OK. My old script has been running for like almost 7 hours now. And my shift is done. LOL I will check it tomorrow. I will add your code to my new script, see what it has to say for itself.

Thanks!


Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • December 29, 2025

OK. My old script has been running for like almost 7 hours now. And my shift is done. LOL I will check it tomorrow. I will add your code to my new script, see what it has to say for itself.

Thanks!

LOL not a problem.  I am interested to see where the differences might be.  Hopefully the new code works too for a more accurate number.

 
 
 

Forum|alt.badge.img+1
  • Author
  • Comes here often
  • December 30, 2025

Also since your script line shows the Library being queried try this code -

$lib = Get-VBRTapeLibrary -Name "YourLibraryName"

Get-VBRTapeMedium |
Where-Object {
$_.LibraryId -eq $lib.Id -and
$_.Location.Type -in @("Slot","Drive") -and
$_.IsFull -eq $true
} |
Select Barcode, MediaPool, Location

 

So I added these lines instead:

 

$lib = Get-VBRTapeLibrary -Name $LibraryName  

Get-VBRTapeMedium -Library $Libraryname | Where-Object {$_.LibraryId -eq $Lib.ID -and $_.Location.Type -in @("Slot","Drive") -and $_.IsFull -eq $true} | Select Barcode, MediaPool, Location
 

I got this:

Barcode   : 018210L7
MediaPool :
Location  : Slot


Barcode   : 018196L7
MediaPool :
Location  : Slot


Barcode   : 018197L7
MediaPool :
Location  : Slot
 

That definitely helped with the speed, thanks!

Now, this command seems to be either hanging, or taking forever:

Get-VBRTapeMediaPool

Doesn’t matter if I pass the Library Name, or the pool ID ….

 

 

 

 

 

 


Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • December 30, 2025

Also since your script line shows the Library being queried try this code -

$lib = Get-VBRTapeLibrary -Name "YourLibraryName"

Get-VBRTapeMedium |
Where-Object {
$_.LibraryId -eq $lib.Id -and
$_.Location.Type -in @("Slot","Drive") -and
$_.IsFull -eq $true
} |
Select Barcode, MediaPool, Location

 

So I added these lines instead:

 

$lib = Get-VBRTapeLibrary -Name $LibraryName  

Get-VBRTapeMedium -Library $Libraryname | Where-Object {$_.LibraryId -eq $Lib.ID -and $_.Location.Type -in @("Slot","Drive") -and $_.IsFull -eq $true} | Select Barcode, MediaPool, Location
 

I got this:

Barcode   : 018210L7
MediaPool :
Location  : Slot


Barcode   : 018196L7
MediaPool :
Location  : Slot


Barcode   : 018197L7
MediaPool :
Location  : Slot
 

That definitely helped with the speed, thanks!

Now, this command seems to be either hanging, or taking forever:

Get-VBRTapeMediaPool

Doesn’t matter if I pass the Library Name, or the pool ID ….

 

 

 

 

 

 

That is great that you go somewhere with speed of the PS command.  Not sure myself why the one cmdlet is taking so long.  Do you have hundreds of tapes in the library?  Just curious if maybe it is bound by the total number of tapes somehow.  I also wonder if you need to specify online only media - maybe it is looking through offline tapes?

Maybe this will do it?

# Get all tapes that are Full but not Offline, and are currently in a library slot or drive
Get-VBRTapeMedium | Where-Object {
$_.IsFull -eq $true -and
$_.IsOffline -eq $false -and
($_.Location.Type -eq "Slot" -or $_.Location.Type -eq "Drive")
} | Select-Object Name, Barcode, IsFull, IsOffline,
@{N='LocationType';E={$_.Location.Type}},
@{N='LibraryName';E={$_.Location.Library.Name}},
@{N='SlotAddress';E={$_.Location.SlotAddress}},
MediaSet, ExpirationDate, LastWriteTime | Format-Table -AutoSize

Might want to try posting this on the Forums at this point to see if any Product Manager might be able to help further as I am out of ideas.  Best of luck and hopefully you can come back with the solution.


Forum|alt.badge.img+1
  • Author
  • Comes here often
  • January 6, 2026

Actually I found out that it was the query for Get-VBRTapeMediaPool that was taking so long.

 

        $TapeMediaPool        = Get-VBRTapeMediaPool -Library $LibraryName -ID $TapeMediaPoolID | Select -ExpandProperty Name

 

I ended up rebooting the server, and then the script (which 2 hrs+ before the reboot) … took 8 minutes after the reboot. Same script, didn’t change a line.

I’m gonna see if we can schedule a weekly reboot, as sort of a preventative maintenance and avoid this kind of grief in future. It had been a few weeks since the last reboot.

 


Chris.Childerhose
Forum|alt.badge.img+21
  • Veeam Legend, Veeam Vanguard
  • January 6, 2026

Actually I found out that it was the query for Get-VBRTapeMediaPool that was taking so long.

 

        $TapeMediaPool        = Get-VBRTapeMediaPool -Library $LibraryName -ID $TapeMediaPoolID | Select -ExpandProperty Name

 

I ended up rebooting the server, and then the script (which 2 hrs+ before the reboot) … took 8 minutes after the reboot. Same script, didn’t change a line.

I’m gonna see if we can schedule a weekly reboot, as sort of a preventative maintenance and avoid this kind of grief in future. It had been a few weeks since the last reboot.

 

Interesting that a reboot made it run faster.  Glad it worked with no changes.