PowerShell script exchange
Post Reply
jabraham
Lurker
Posts: 2
Liked: never
Joined: May 01, 2020 6:57 pm
Full Name: Joseph Abraham
Contact:

Powershell VBR Variables

Post by jabraham »

Hi,
I am trying to automatically export a csv file, however I am trying to look for a couple of variables to use.

I have this so far:

Code: Select all

Add-PSSnapin VeeamPSSnapin

Get-VBRTapeMedium | Sort-Object {$_.Barcode} |Select-Object -Property @{N="Barcode";E={$_.Barcode}}, 
@{N="Location";E={$_.Location, $_.Location.SlotAddress}}, 
@{N="IsExpired";E={IF($_.isExpired){"Expired"}Else{$_.ExpirationDate}}}, 
@{N="Media Set";E={$_.MediaSet}}, 
@{N="Capacity";E={[math]::Round($_.Capacity/1TB, 2), "TB"}}, 
@{N="Free Space";E={[math]::Round($_.Free/1TB, 2), "TB"}},
@{N="Desciption";E={$_.Description}} | Export-Csv -Path C:\util\VEEAMInventory.csv
I am trying to look for the Media Pool Name variable to show what category each of the tapes belong to. Also I am trying to look for the Tape Library Name, however I cannot find the variables for these.

I think I have to combine another Get-VBR but I don't know how to combine two Get statements. Any help would be appreciated!

-Joseph
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Powershell VBR Variables

Post by oleg.feoktistov » 1 person likes this post

Hi Joseph,

Looping through each tape medium can help. Also, as a best practice, I'd assign all possible calculations to variables before passing them to property expressions:

Code: Select all

# Get all tape mediums
$tapemediums = Get-VBRTapeMedium | Sort-Object {$_.Barcode}

# Build null array 
$tapeInfo = @()

# Loop through each tape medium
foreach ($tapemedium in $tapemediums) {

# Perform calculations
if ($tapemedium.IsExpired -eq $True) 
{ $expiration = 'Expired' } 
else 
{ $expiration = $tapemedium.ExpirationDate }
$capacity = [math]::Round($tapemedium.Capacity/1TB, 2), "TB"
$freeSpace = [math]::Round($tapemedium.Free/1TB, 2), "TB"
$location = [System.String]::Join(", ", $tapemedium.Location, $tapemedium.Location.SlotAddress)

# Get media pool for current tape medium by media pool id
$mediapool = Get-VBRTapeMediaPool | where {$_.Id -eq $tapemedium.MediaPoolId}

# Get library for current tape medium by library id
$library = Get-VBRTapeLibrary | where {$_.Id -eq $tapemedium.LibraryId}

# Add newly built hashtable to $tapeInfo array in every loop cycle
$tapeInfo += $tapemedium |Select-Object -Property @{N="Barcode";E={$_.Barcode}}, 
@{N="Location";E={$location}}, 
@{N="IsExpired";E={$expiration}}, 
@{N="Media Set";E={$_.MediaSet}}, 
@{N="Capacity";E={$capacity}}, 
@{N="Free Space";E={$freeSpace}},
@{N="Media Pool";E={$mediapool.Name}},
@{N="Library";E={$library.Name}}
}

# Export array of constructed objects to csv file
$tapeInfo | Export-Csv -Path C:\Temp\VEEAMInventory.csv -Append 

Thanks,
Oleg
jabraham
Lurker
Posts: 2
Liked: never
Joined: May 01, 2020 6:57 pm
Full Name: Joseph Abraham
Contact:

Re: Powershell VBR Variables

Post by jabraham »

Dear Oleg,

Thank you very much for your input and code Oleg. This is so helpful.

Got it down to the dot. Much appreciated.

From,
Joseph
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests