Showing results for 
Search instead for 
Did you mean: 


This Powershell script is a follow-up to my earlier script
to import tapes into the first empty slot of a tape library.  
With the advent of BE 2012 and the introduction of BEMCLI, the earlier script which is based on BEMCMD cannot be used in BE 2012.  Since BEMCLI has a richer set of cmdlets, this script also clears the media intervention alert asking you to put a tape into the mail/io slot.  Previously, this clearance is not possible and it resulted in a 20 minutes wait for the alert to expire which eats into the backup window.
This script would not have been possible with the many contributions from Martin Hess who also tested it.
To use this script, make sure that you have changed your Powershell execution policy so that you can run scripts.  See my article below on how to do so
Before you use, you need to find out the name of your tape library.  Launch BEMCLI and then issue this command.
Get-BERoboticLibraryDevice | Select-Object name
You would need the name of the library as an input parameter to the script.
If you have imported the BEMCLI module in your profile, then you can comment out the Import-Module command in the script.
To run the script as a pre-/post-command, use a statement like this
c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe 'c:\Import-FirstEmptySlot.ps1' '"HP 002"'
This assumes that the script is kept in the root directory of the C: drive.  The library name, e.g. HP 002, must be surrounded by single quotes (') and the double-quotes (").


The script runs and generates the following output:

BEMCLI> .\import-FirstEmptyslot.ps1 "Robotic Library 0001"

Name     : Media Request
Severity : Question
Category : MediaIntervention
Date     : 18.05.2012 11:45:25
Message  : Please insert media into the portal.

           Respond OK to acknowledge.
           Respond Cancel to cancel the operation.


After this, the script terminates. In BE, there's a running job waiting for a tape in the mailslot.

So script must be run with a tape already in the mailslot.  Otherwise, the import job will hold up the library while waiting for the missing tape.  This is the same behaviour as in previous versions of BE.

This problem of not having a tape in the mailslot during the automated import can be solved by adding the 

-CancelJobIfRunningAfterScheduledTimeBy <TimeSpan>

switch to the Submit-BEImportMediaJob cmdlet in the script.

This solution is suggested by another user for the other import script

I couldn't find any reference which defined the <TimeSpan> parameter; fixed the import job holding up the library while the importslot was not populated by adding the following lines at the end of import-FirstEmptyslot.ps1  :

Start-Sleep -sec 120
$MediaInterventionAlert = Get-BEAlert -Storage $name -Category MediaIntervention
if ($MediaInterventionAlert -ne $Null) {
 Clear-BEAlert -in $MediaInterventionAlert -Response cancel -Confirm:$false