PowerShell script exchange
Post Reply
MikeLeone
Enthusiast
Posts: 28
Liked: 2 times
Joined: Sep 21, 2022 3:03 pm
Full Name: Michael Leone
Contact:

Get list of all tapes currently in library (slots and drives)

Post by MikeLeone »

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 (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?
david.domask
Veeam Software
Posts: 3180
Liked: 736 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get list of all tapes currently in library (slots and drives)

Post by david.domask »

Hi MikeLeone,

When you say monumentally slow, can you give a time value for this? Please show the output of:

Code: Select all

Measure-Command -Expression {Get-VBRTapeMedium}
Measure-Command -Expression {Get-VBRTapeMedium -Library $LibraryName | Where {{$_.IsFull -eq $TRUE}} | Select Name, LastWriteTime, MediaPoolID, IsFull, Location | Sort -Property MediaPoolID, Name}
(Get-VBRTapeMedium -Library $LibraryName | Where {{$_.IsFull -eq $TRUE}}).Count
Potentially, you could parse through media pools with Get-VBRTapeMediaPool and pull out IsFull from that, but depending on the number of tapes in each media pool that may be slow as well.

Basically, I suspect we may need a case to review the behavior here but would be curious at first to understand how slow is "slow".

Similarly, I'm curious if it works better without the Select / Sort in the same line -- Select will build a PSCustomObject for each item piped to it, and I suspect that this may be the cause of the long-running command, and breaking the pipeline up into separate lines may help.
David Domask | Product Management: Principal Analyst
MikeLeone
Enthusiast
Posts: 28
Liked: 2 times
Joined: Sep 21, 2022 3:03 pm
Full Name: Michael Leone
Contact:

Re: Get list of all tapes currently in library (slots and drives)

Post by MikeLeone »

I was mistaken, the slowness comes from this command:

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

For example, the latest run of the program found 6 tapes to match. It took over 2 hours to match 6 tapes by TapeMediaPoolIID ..

Execution Time: 02:02:37.5152598 Script Run Date: 01/01/2026 08:03:52

I will re-run the script, with Write-Verbose showing various start times, and post the code here later.
david.domask
Veeam Software
Posts: 3180
Liked: 736 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Get list of all tapes currently in library (slots and drives)

Post by david.domask »

Thanks for the update, Get-VBRTapeMediaPool makes a bit more sense to me as the returned object will have all of the tapes added to the media pool as part of the returned object under the Medium property, so I'm guessing building the object is what takes awhile -- for the media pool you tested with, how many tapes are added to the media pool?

Will discuss internally on how we can improve performance for Get-VBRTapeMediaPool, but for your scripting needs, use Get-VBRTapeMedium and consider filtering first on the Location.Type property and only pull tapes in slot / drive -- it should be much faster.
David Domask | Product Management: Principal Analyst
MikeLeone
Enthusiast
Posts: 28
Liked: 2 times
Joined: Sep 21, 2022 3:03 pm
Full Name: Michael Leone
Contact:

Re: Get list of all tapes currently in library (slots and drives)

Post by MikeLeone »

I have these pools: (I will add the totals in the pools by hand, since I can't take the time to wait for a new script to pull them out ..)

PS P:\software\PHA Scripts> Get-VBRTapeLibrary | Get-VBRTapeMediaPool | Select Name, Id Name Id ---- --
PHACLONE 747
Free 7
Imported
PROD-DMZ 6
PROD-SCADA 3
Retired 1
PROD-FileServer INCREMENTAL 0
PROD-Telecom 9
PROD-Scanning 20
PROD-APP and WEB Servers 21
Media Pool 1 7
DEV-DBs and Log Shipping 65
DEV-FileServer Related 8
PROD-Mail Related 175
DEV-App and Web Servers 26
Unrecognized 1
PROD-FileServer Related 117
PROD-DBs and Log Shipping 58
PROD-FileServer FULL 48
PROD-Networking Management 38

Here are the tapes I was looking up. there are 5 ...

1. 018139L7 12/30/2025 14:28:10 PHACLONE
2. 018196L7 12/30/2025 06:51:05 PHACLONE
3. 018197L7 12/30/2025 05:08:46 PROD-DBs and Log Shipping
4. 018210L7 12/29/2025 16:32:31 PROD-FileServer Related
5. 018208L7 12/30/2025 12:14:57 PROD-Mail Related
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest