DPM 2010 Script to run inventory, then mark tape as free

HI There,

We recently have setup a DPM 2010 Server backing up our corporate network.
Our server has a stand alone LTO 5 tape drive.
Our tape calendar is a full backup following the days:
Monday,Tuesday, Wednesday, Thursday, Friday 1, Friday 2, Friday 3, Friday 4, Friday 5
Along with Month Ends and Week Ends.
Because we are not the most organised bunch, we would like whatever tape that gets put it to be written to so I have been using the script attached below.
The script works fine but requires the manual input of server name and tape drive name. It also fails if an inventory is not run prior to the script being ran.

So my question is:
Can someone show me how to automate the following and add an inventory to the start of the the script so I can run it as a scheduled task before each night's backup.
My server Name is: STL-DPM1
My Tape Drive Name is: Hewlett Packard LTO Ultrium-5 drive

Here is the current script:

 }
 if (!$LibraryName)
 {
     $LibraryName = Read-Host "Library name: "
     if (!$LibraryName)
     {
         Write-Error "Library name not specified."
         exit 1
     }
 }
 

if (!(Connect-DPMServer $DPMServerName))
 {
     Write-Error "Failed to connect To DPM server $DPMServerName"
     exit 1
 }
 $library = Get-DPMLibrary $DPMServerName | where {$_.UserFriendlyName -eq $LibraryName}
 write-host "Getting library..."
 if (!$library)
 {
     Write-Error "Failed to find library with user friendly name $LibraryName"
     exit 1
 }
 foreach ($media in @(Get-Tape -DPMLibrary $library))
 {
 write-host "Getting media..."
 
        if ($media -is [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.LibraryManagement.ArchiveMedia])
         {
             foreach ($rp in @(Get-RecoveryPoint -Tape $media))
             {
   write-host "Getting recovery point..."
                 Get-RecoveryPoint -Datasource $rp.Datasource | Out-Null
                 Write-Verbose "Removing recovery point created at $($rp.RepresentedPointInTime) for tape in $($media.Location)."
                 write-host "Force removing recovery point..."
   Remove-RecoveryPoint -RecoveryPoint $rp -ForceDeletion -Confirm:$false
             }
             Write-Verbose "Setting tape in $($media.Location) as free."
      write-host "Setting tape as free..."
             Set-Tape -Tape $media -Free
         }
         else
         {
             Write-Error "The tape in $($media.Location) is a cleaner tape."
         }
   
 
}
St_LukesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
d3ath5tarConnect With a Mentor Commented:
Ohhhhh I frogot a bit....

the first line of DoInventory.ps1 needs to be;
Add-PSSnapin -name Microsoft.DataProtectionManager.PowerShell

So the whole file is;
Add-PSSnapin -name Microsoft.DataProtectionManager.PowerShell
$DPMServerName = $env:computername
$DPMLibrary = get-dpmlibrary -DPMServerName $DPMServerName
Start-DPMLibraryInventory -DpmLibrary $DPMLibrary[1]

0
 
d3ath5tarCommented:
if the script is running directly on your dpm server;

$DPMServerName = $env:computername (if you are running this remotely then replace $env:computername with a string value.

then get your library details
$DPMLibrary = get-dpmlibrary -DPMServerName $DPMServerName

The library in your tape unit would normally be listed as the second entry, which is entry 1 as the devices start at 0.... but you could run the above once manually to be sure.... but when you know the next line would be..

Start-DPMLibraryInventory -DpmLibrary $DPMLibrary[1] (unless 1 -i,e, the second device, wasn't your library locatioN)

You could also a -DetailedInventory to the command if you want a thorough one...



 
0
 
St_LukesAuthor Commented:
d3ath5tar:

Thanks for the info, unfortunately I have no idea about this scripting so I was looking for someone to put it together for me cheers. I will be running it locally also.
0
 
d3ath5tarCommented:
OK....

Open a powershell window and run;
set-remoteexecutionpolicy remotesigned
Close powershell

Each line of script will do the trick if you run it on your local dpm server so open notepad and paste in;

$DPMServerName = $env:computername
$DPMLibrary = get-dpmlibrary -DPMServerName $DPMServerName
Start-DPMLibraryInventory -DpmLibrary $DPMLibrary[1]

Save all that in c:\support\DoInventory.ps1 and launch it from a scheduled task before your backup kicks off...

To schedule a powershell job as a task, open scheduled tasks and create your task as teh command;
powershell -command "& C:\support\DoInventory.ps1' "

As far as working out if the $DPMLibrary[1] is correct; open powershel and run the first two lines manually
Then typr $DPMLibrary on it own; it will list all your back up objects e.g.

Tape something or other
Library name something or other
maybe more devices

Eahc line is a line starting from 0, so look for the line with your library name in it... it should be then second line which is 1.

If it is not one, replace one with the correct array line number remembering to count lines starting from 0.

0
 
St_LukesAuthor Commented:
Was a bit staggered and hard to follow. Required further assistance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.