PowerShell script exchange
Post Reply
ithark
Enthusiast
Posts: 40
Liked: 6 times
Joined: Sep 30, 2020 11:22 am
Full Name: Karthik
Contact:

To get media pool name from the Get-VBRTapeMedium command output.

Post by ithark »

Dear All,
I got this powershell script from the forums and it is working very well. But the only requirement I have is to get the Media pool name instead of the Media pool ID. Since I don't have much expertise on power shell scripting, I am posting this here to get your help on this.
Many thanks in advance.

Code: Select all

#Add Veeam Snap In
Add-PSSnapin -Name VeeamPSSnapIn

#Mail Server Variables
#$recipients = ""
$recipients = ""
$smtpServer = ""
$smtpFrom = ""
$smtpTo = "$recipients"
$messageSubject = "Tapes ready for offsite - amSI Backups"

#Message Variables
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
$Header = @"
<style>
BODY{font-family: Calibri; font-size: 11pt;}
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 6px;border-style: solid;border-color: black;background-color: #63C1ED;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@

#Veeam Tape Variables
$x=(get-date).adddays(-7)
$tapes = Get-VBRTapeMedium | where {$_.LastWriteTime -gt $x} |select Name,LastWriteTime,ExpirationDate,MediaPoolId,Location |Sort-Object Name,ExpirationDate | ConvertTo-Html -Head $Header

#Message Body

$bodyline1 = "<DIV style=font-size:11pt;font-family:Calibri> <p>The following tapes are ready to be sent offsite. Please replace with free ones:<br><br></p></DIV>"
$message.Body= $bodyline1 + $tapes

#Send the Message
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
Regards,
Karthik
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: To get media pool name from the Get-VBRTapeMedium command output.

Post by oleg.feoktistov » 1 person likes this post

Hi @ithark

You'd need to get all media pools, search media pool name by its id each iteration and construct a new object with media pool name instead of id:

Code: Select all

#Veeam Tape Variables
$x=(get-date).adddays(-7)

# Get all tape media pools
$tapePools = Get-VBRTapeMediaPool

# Get tape mediums
$tapes = Get-VBRTapeMedium | where {$_.LastWriteTime -gt $x} 
$tapesTotal = @()


foreach ($tape in $tapes) {

    # Query media pools array for one with the corresponding id
    $pool = $tapePools | where {$_.Id -eq $tape.MediaPoolId}
    
    # Compose a new object with media pool name as a property and assign to an empty array
    $tapesTotal += $tape |select Name, LastWriteTime, ExpirationDate, @{n='MediaPoolName';e={$pool.Name}},Location `
    |Sort-Object Name,ExpirationDate | | ConvertTo-Html -Head $Header
} 
ithark
Enthusiast
Posts: 40
Liked: 6 times
Joined: Sep 30, 2020 11:22 am
Full Name: Karthik
Contact:

Re: To get media pool name from the Get-VBRTapeMedium command output.

Post by ithark »

Thank you @oleg.feoktistov Much appreciated
Regards,
Karthik
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 11 guests