Backup Exec 2012 Tape Usage Report with PowerShell

Back in December 2011 Jeff Hicks posted this  drive usage console graph article on his blog. While I thought it was awesome, I was still learning PowerShell and didn’t understand how he achieved all of this.

Over the last couple of months I have kept coming back to this post. I wanted to implement the percentage free graph into something other then drive space.

Yesterday it hit me! While I was poking around in Backup Exec’s BEMCLI PowerShell module I noticed that you could pull stats from the tapes in the library. Doing this in itself is pretty easy, typing Get-BEMedia will get you all of the media available. Get-BEMedia –Name <Tape Name> will bring up the details for a specific tape.

image

Piping this command to Get-Member will give you all the properties you can pull information from.

image

The 2 properties we are after are TotalCapacityBytes and UsedCapacityBytes.

To view these properties need to create a variable like so;

$BEM1=Get-BEMedia –Name LTO000010

From there we can get the total and used capacity bytes:

$BEM1.TotalCapacityBytes
$BEM1.UsedCapacityBytes

You can also divide by GB or TB depending on your LTO tape size.

image

 

I changed about 13 lines of code (including comments) to get it working with Backup Exec 2012. It provides a good snapshot of data availability for each tape, but I am already looking at improving it further.

You will need to import-module BEMCLI first then you can run the script. You can specify tapes individually or create a variable to display all tapes in a media set.

Examples:

Get-BETapeUsage –tapes LTO000010

$BEM1=Get-BEMedia – MediaSet “Keep Data for 4 Weeks”
Get-BETapeUsage –tapes $BEM1

image

 

#requires -version 2.0

Param (
 [string[]]$tapes=@("tapea","tapeb","tapec")
 )

#get the current window width so that our lines will be proportional
 $Width = $Host.UI.RawUI.BufferSize.Width/2

$data=Get-BEMedia -Name $Tapes

#get length of longest tape name so we can pad
 $longest=$data | select -ExpandProperty Name | sort Length | select -last 1

#group data by name
 $groups=$Data | Group-Object -Property Name

Clear-Host
 Write-Host ("`n{0} {1}`n" -f "Backup Exec 2012 Tape Usage Report",(Get-Date)) -ForegroundColor Yellow

#iterate through each group object
 ForEach ($tape in $groups) {

    #define a collection of tapes from the group object
     $Drives=$tape.group

    #iterate through each tape in the media set
     Foreach ($drive in $drives) {
         $FreeDividedSize=$drive.AvailableCapacityBytes/$drive.TotalCapacityBytes
         [string]$PerFree="{0:P}" -f $FreeDividedSize
         [int]$FreePad=$Width*$FreeDividedSize 

        $Used=$drive.TotalCapacityBytes - $drive.AvailableCapacityBytes
         $UsedDividedSize=$used/$drive.TotalCapacityBytes
         [string]$perUsed="{0:P}" -f $UsedDividedSize
         [int]$UsedPad=$Width*$UsedDividedSize

        #not currently used
         [string]$UsedGB="{0:N2}GB " -f ($Used/1GB)
         [string]$FreeGB="{0:N2}GB " -f ($drive.AvailableCapacityBytes/1GB)

        #this is the graph character
         [string]$g=[char]9608
        [string]$freeGraph=$g*($FreePad)
         [string]$UsedGraph=$g*($UsedPad)  

        write-host ("[{0}] {1} " -f $drive.name.PadRight($longest.length),$drive.DeviceID)  -NoNewline
         write-host $freeGraph -ForegroundColor darkgreen -NoNewline
         write-host $UsedGraph -ForegroundColor red -NoNewline
         write-host (" {0} free " -f $PerFree)

        #insert a return between each drive
         write-host "`r"
     } #foreach drive
     #insert a blank line between computers if you want
     #Write-host "`n"
 } #foreach computer
Advertisements

About Phill McSherry
Phill McSherry has been working in the Australian IT industry for over 20 years and is the technical manager and solutions architect for managed services provider Titan Solutions - www.titansolutions.com.au

2 Responses to Backup Exec 2012 Tape Usage Report with PowerShell

  1. Excellent. As great as your solution is, I think even more awesome is the process you took to arrive at it using cmdlets like Get-Member. Great work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: