I come across one of the many questions, someone asked me if they can erase the tapes manually before it’s expired. They said they wanted to do some testing to backup to tapes but somehow they can’t be able to find the erasure in the GUI.
So I’m going to share how it is done using PowerShell.
Launch the DPM console. Navigate to the Management – Libraries . Take note of it. Slot 1 to Slot 9 .
Then now open a notepad. Copy and paste the following (in yellow) to it :
param ([string] $DPMServerName, [string] $LibraryName, [string[]] $TapeLocationList)
if(("-?","-help") -contains $Args[0])
{
Write-Host "Usage: ForceFree-Tape.ps1 [[-DPMServerName] <Name of the DPM server>] [-LibraryName] <Name of the library> [-TapeLocationList] <Array of tape locations>"
Write-Host "Example: Force-FreeTape.ps1 -LibraryName "My library" -TapeLocationList Slot-1, Slot-7"
exit 0
}
if (!$DPMServerName)
{
$DPMServerName = Read-Host "DPM server name: "
if (!$DPMServerName)
{
Write-Error "Dpm server name not specified."
exit 1
}
}
if (!(Connect-DPMServer $DPMServerName))
{
Write-Error "Failed to connect To DPM server $DPMServerName"
exit 1
}
$library = @(Get-DPMLibrary $DPMServerName )
if ($library.count -eq 0)
{
Write-Error "Failed to find library with user friendly name $LibraryName"
exit 1
}
if (!$LibraryName)
{
$library | foreach {$_.userfriendlyname}
$LibraryName = Read-Host "Library name (cut & paste from above): "
if (!$LibraryName)
{
Write-Error "Library name not specified."
exit 1
}
}
if (!$TapeLocationList)
{
$tmp = Read-Host "Tape location: "
$TapeLocationList=$tmp.split(",")
write-host "Processing this slot list..."
$TapeLocationList
if (!$TapeLocationList)
{
Write-Error "Tape location not specified."
exit 1
}
}
foreach ($media in @(Get-Tape -DPMLibrary $library))
{
if ($TapeLocationList -contains $media.Location)
{
if ($media -is [Microsoft.Internal.EnterpriseStorage.Dls.UI.ObjectModel.LibraryManagement.ArchiveMedia])
{
foreach ($rp in @(Get-RecoveryPoint -Tape $media))
{
Get-RecoveryPoint -Datasource $rp.Datasource | Out-Null
Write-Verbose "Removing recovery point created at $($rp.RepresentedPointInTime) for tape in $($media.Location)."
Remove-RecoveryPoint -RecoveryPoint $rp -ForceDeletion -Confirm:$false
}
Write-Verbose "Setting tape in $($media.Location) as free."
Set-Tape -Tape $media -Free
}
else
{
Write-Error "The tape in $($media.Location) is a cleaner tape."
}
}
}
Save the file and rename it with the extension .ps1
In my example here, I have a file name as Tape_Erase.ps1 and stored in the D:\PowerShell Scripts directory.
From the DPM console, I launch the DPM Management Shell (which is the PowerShell)
Once launch you’ll be able to see the screen as above.
Then I change to the directory to where I save my PowerShell Script. In my case I maneuvered to “D:\PowerShell Scripts”.
To execute the PowerShell script I keyed in with a ./
In my example my file is name as tape_erase.ps1. To execute the script I type as ./tape_erase.ps1 .
Then next I keyed in the DPM server name (that is with the tape library). In my case is MY-VM-DPM-SEC01
Then I key in the tape slot that I want to erase the tape.
I keyed in as Slot-2.
Note : the ones in pink are the ones that needs to be change accordingly to your naming of your PowerShell script and your DPM settings.
Then you’ll be able to see the process followed.
Another example as above, which I want to erase the tape in Slot-9. e.g. In some cases the name of slot could be Slot-9 or Slot 9. So it differs from one tape library to another.
Once it’s done, launch back the DPM Console.
Click on the Management tab, then on the Libraries tab.
Select the tape that was erase earlier. In my example is Slot 2. <Right-click> on the tape and select Erase tape.
Click Yes.
Now the tape is erased and ready to be reuse.
Thank you and hope it helps you. A special thanks also to Ruud Baars (of Microsoft) for sharing his scripting.
keywords : Data Protection Manager, erase tape before expire in DPM, how to erase tape manually in DPM, PowerShell script to erase tape manually in DPM.