PowerShell script exchange
Post Reply
StevenYong
Novice
Posts: 6
Liked: 4 times
Joined: May 13, 2016 7:43 am
Full Name: Steven Yong Yin Heong
Contact:

Require last 24 hours used tape report (Case # 01799426)

Post by StevenYong »

Hi All,

Urgently require last 24 hours used tape report.

Best Regards,
Steven Yong
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by PTide » 1 person likes this post

Hi,

Please try this quick and dirty one:

Code: Select all

$x=(get-date).adddays(-1)
Get-VBRTapeMedium | where {$_.LastWriteTime -gt $x}
The output will contain all tapes that have been used during previous 24 hours from current date and time. You might be also interested in Veeam ONE reporting capabilities.


Thanks
StevenYong
Novice
Posts: 6
Liked: 4 times
Joined: May 13, 2016 7:43 am
Full Name: Steven Yong Yin Heong
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by StevenYong »

Hi PTide,

Awesome!!! Tested the script and it able capture last 24 hours used tape.

Will consider VEEAM ONE report but cost will be concern. ^.^

Thanks
StevenYong
Novice
Posts: 6
Liked: 4 times
Joined: May 13, 2016 7:43 am
Full Name: Steven Yong Yin Heong
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by StevenYong » 1 person likes this post

Hi Ptide,

While we try run script below manually its show the result but when we schedule it in task scheduler it show us blank result.

Anything missing in my script?

my script:

Code: Select all

#Add Veeam Snap In
Add-PSSnapin -Name VeeamPSSnapIn

#Mail Server Variables
$recipients = "recipients1@hpe.com, recipients1@hpe.com"
$smtpServer = "smtp server IP"
$smtpFrom = "Hallow@veeam.com"
$smtpTo = "$recipients"
$messageSubject = "Veeam Tape Ejection Report"

#Message Variables
$message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true

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

#Message Body
$Header = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 10px;border-style: solid;border-color: black;background-color: #6495ED;}
TD {border-width: 1px;padding: 10px;border-style: solid;border-color: black;}
</style>
"@
$bodyline1= "<p>Please eject the following tapes from the tape loader and replace them with fresh tapes <br><br></p>"
$message.Body = $bodyline1 + $tapes

#Send the Message
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
StevenYong
Novice
Posts: 6
Liked: 4 times
Joined: May 13, 2016 7:43 am
Full Name: Steven Yong Yin Heong
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by StevenYong » 2 people like this post

Got the solution already (User Access right issue)

Thank you
nickl99
Enthusiast
Posts: 29
Liked: 4 times
Joined: Aug 03, 2016 5:09 am
Full Name: NICK LAING
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by nickl99 »

I have modified the above script as shown beliw and it is working well, except I would like to add a field for retention date in the email. I have posted what I am receiving as email.

Code: Select all

asnp VeeamPSSnapIn
$smtp = "mail.server.com
$to = "IT@server.com
$from = "backup@domain.com
$subject = "Weekly Tape Swap for $Date" 
$x=(get-date).adddays(-3)
$tapes = Get-VBRTapeMedium | where {$_.LastWriteTime -gt $x} |select Name,LastWriteTime |Sort-Object Name | ConvertTo-Html -Head $Header
[string]$body = $tapes
send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml
I receive:
Name LastWriteTime
CDX116L6 27/09/2016 5:25:44 AM
CDX119L6 26/09/2016 4:51:19 AM
CDX122L6 26/09/2016 1:02:47 AM
CDX127L6 25/09/2016 5:36:08 PM
CDX128L6 26/09/2016 4:35:52 PM
CDX131L6 27/09/2016 3:43:00 AM
nickl99
Enthusiast
Posts: 29
Liked: 4 times
Joined: Aug 03, 2016 5:09 am
Full Name: NICK LAING
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by nickl99 » 1 person likes this post

Answered my question thanks
Stan-san
Influencer
Posts: 17
Liked: 6 times
Joined: Feb 17, 2017 9:32 pm
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by Stan-san » 3 people like this post

Hello all,

below is the script which I improved and adapted for my needs. Credits go to the authors. It is scheduled for Tuesday, queries tape jobs 4 days back (this way it covers my weekend tape jobs) and sends a table with Name, LastWriteTime, ExpirationDate, MediaSet. Change the mail server variables as per your environment. You can also add or remove columns. The complete list of what you can use is also below (you can get it by running Get-VBRTapeMedium https://helpcenter.veeam.com/docs/backu ... tml?ver=95).

Code: Select all

#Add Veeam Snap In
Add-PSSnapin -Name VeeamPSSnapIn

#Mail Server Variables
$recipients = "Bill.Gates@microsoft.com"
$smtpServer = "8.8.8.8"
$smtpFrom = "VeeamAlerts@veeam.com"
$smtpTo = "$recipients"
$messageSubject = "Tapes ready for offsite"

#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(-4)
$tapes = Get-VBRTapeMedium | where {$_.LastWriteTime -gt $x} |select Name,LastWriteTime,ExpirationDate,MediaSet |Sort-Object MediaSet,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)
  • Barcode
    HasBarcode
    Free
    Capacity
    Location
    PreviousLibraryId
    PreviousMediaPoolId
    SequenceNumber
    ExpirationDate
    MediaPoolId
    MediaSet
    LibraryId
    LastWriteTime
    IsFree
    IsFull
    IsLocked
    IsRetired
    IsExpired
    ProtectedBySoftware
    ProtectedByHardware
    Id
    Name
    Description
chris.childerhose
Veeam Vanguard
Posts: 636
Liked: 154 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by chris.childerhose »

I am trying to use this report but also include the media pool name so that I know what the tape was used for other than the Media Set. None of the columns seem to pull that unless I am missing something?
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by veremin »

VBRTapeMedium entity has MediaPoolId property indicating the ID of the media pool to which the tape belongs. Thanks.
chris.childerhose
Veeam Vanguard
Posts: 636
Liked: 154 times
Joined: Aug 13, 2014 6:03 pm
Full Name: Chris Childerhose
Location: Toronto, ON
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by chris.childerhose »

Yes but this comes up as a long string of alphanumeric characters. I want just the Description of it versus the ID itself.
-----------------------
Chris Childerhose
Veeam Vanguard / Veeam Legend / Veeam Ceritified Architect / VMCE
vExpert / VCAP-DCA / VCP8 / MCITP
Personal blog: https://just-virtualization.tech
Twitter: @cchilderhose
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Require last 24 hours used tape report (Case # 01799426)

Post by veremin »

Utilizing this ID, you can get a media pool and its name, using Get-VBRTapeMediaPool cmdlet. Then, it's just a matter of compiling everything together. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests