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

PowerShell script exchange

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

Veeam Logoby StevenYong » Thu May 19, 2016 6:40 am

Hi All,

Urgently require last 24 hours used tape report.

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

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

Veeam Logoby PTide » Thu May 19, 2016 10:28 am 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
PTide
Veeam Software
 
Posts: 3134
Liked: 262 times
Joined: Tue May 19, 2015 1:46 pm

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

Veeam Logoby StevenYong » Fri May 20, 2016 12:13 am

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: Fri May 13, 2016 7:43 am
Full Name: Steven Yong Yin Heong

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

Veeam Logoby StevenYong » Tue May 24, 2016 2:10 am 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: Fri May 13, 2016 7:43 am
Full Name: Steven Yong Yin Heong

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

Veeam Logoby StevenYong » Tue May 24, 2016 2:56 am 2 people like this post

Got the solution already (User Access right issue)

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

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

Veeam Logoby nickl99 » Tue Sep 27, 2016 3:56 am

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:
NameLastWriteTime
CDX116L627/09/2016 5:25:44 AM
CDX119L626/09/2016 4:51:19 AM
CDX122L626/09/2016 1:02:47 AM
CDX127L625/09/2016 5:36:08 PM
CDX128L626/09/2016 4:35:52 PM
CDX131L627/09/2016 3:43:00 AM
nickl99
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Wed Aug 03, 2016 5:09 am
Full Name: NICK LAING

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

Veeam Logoby nickl99 » Tue Sep 27, 2016 5:57 am 1 person likes this post

Answered my question thanks
nickl99
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Wed Aug 03, 2016 5:09 am
Full Name: NICK LAING

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

Veeam Logoby Stan-san » Tue Mar 28, 2017 3:02 pm 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/backup/powershell/get-vbrtapemedium.html?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
Stan-san
Influencer
 
Posts: 17
Liked: 6 times
Joined: Fri Feb 17, 2017 9:32 pm


Return to PowerShell



Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests