I quickly knocked up this Powershell script to format all the tapes in one of my TL2000 Tape Libraries using the Backup Exec tool BEMCMD.

The script basically gets the library name, then scans each slot (there are 23) to see if the slot is either empty or a cleaning tape and if its not empty and not a cleaning tape then it creates a Format Media job in Backup Exec for processing.


c:
cd “\Program Files\Symantec\Backup Exec”
#
# Get Library Name and get rid of blank lines in output
#
$a=.\bemcmd -o84 -j|where {$_ -ne “”}
#
# Seperate Device name
#
$o = $a[0].split(“:”)
$device=$o[1].Trim()

$i=1
while($i -le 22)
{
#
# check if empty
#
$c=”.\bemcmd -o86 -s”+$i+” -d”+'”‘+$device+'”‘
$o=cmd /c $c
$cleaningline=$o[2].trim()
$f=$line.split(“:”)
$cleaningstatus=$f[1].trim()
if( $cleaningstatus -eq “NO” )
{
#
# Check media ID = cannot be 0!
#
$medialine=$o[5].split(“:”)
$mid=$medialine[1].trim()
if( $mid -eq “{00000000-0000-0000-0000-000000000000}”)
{
“Slot “+$i+” has no media”
}
else
{
#
# execute the format of the tape in slot 1
#
“Slot “+$i+” has id: “+$mid
$c=”.\bemcmd -o114 -s”+$i+” -pr:Low -d”+'”‘+$device+'”‘
cmd /c $c
}
}
$i++
}

To run this script, copy and paste it using notepad and save as format-library.ps1 then to run it from a shell, use powershell c:\scripts\format-library.ps1 (or whereever you put the script).

Advertisements