DPM 2010 Free Tape with Power Shell Update


This is an update to a previous post on how to mark a tape as "free".  Because of limitations with the DPM GUI a Power Shell script must be run to free the tapes associated with protection groups.

I ran into a problem specifying the location of the tape when using the previous script.  The PS script below sidesteps the location problem.

N. B. Here is the correct format to run the script:

PS C:\scripts> .\free2.ps1 -dpmservername dpserver01 -LibraryName "Hewlett Packard DAT72 drive"
Here is the script:

    param ([string] $DPMServerName, [string] $LibraryName)
    if(("-?","-help") -contains $args[0])
    {
        Write-Host "Usage: ForceFree-Tape.ps1 [[-DPMServerName] ] [-LibraryName]  
        Write-Host "Example: Force-FreeTape.ps1 -Dpmservername SDPM01 -LibraryName   My library
        exit 0
    }
    if (!$DPMServerName)
    {
        $DPMServerName = Read-Host "DPM server name: "
        if (!$DPMServerName)
        {
            Write-Error "Dpm server name not specified."
            exit 1
        }
    }
    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."
            }
       
    
    }

0 Comments:

Post a Comment

My Instagram