CLI Script: Force mark tape as free - The Official System Center Data Protection Manager Team Blog - Site Home - TechNet Blogs

CLI Script: Force mark tape as free

CLI Script: Force mark tape as free

  • Comments 16
  • Likes

This script allows a user to mark any tape as free so that it is available for protection by DPM. Tapes which have unexpired data cannot be marked as free from the GUI but sometimes (esp. while testing) users need to override this behaviour.

Save this script as a .ps1 file and run it. Usage and examples of scripts can be found by calling them with ‘-?’ or ‘-help’ from inside DPM Management Shell. 

----------------------------- Start of Script --------------------------------

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."
}
}
}

----------------------------- End of Script ---------------------------------

- Mohit Chakraborty / Ruud Baars

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • This is great but how would I modify it to work with a Stand-alone Drive (no library of tapes)?

  • &#160; When running System Center Data Protection Manager 2007 and utilizing the DPM tape libraries capability

  • Hi,

    my question is:

    How would this script have to be modified in order to be used without user input?

    Say, if I want to make a scheduled task that marks the tape in the stand-alone-drive "free" 1h before the D2T job every day. The script called by that task would have to run with all the necessary information already hard-coded into it. But I have no clue as to where to input these points of data.

  • I have a DPM server with two libraries attached. When I used the script to mark as free slot-5 in second library, it marked as free slot-5 on both libraries !

  • It would be useful if this script could be modified to mark tapes as free beyond a certain age.

    e.g. mark all tapes as free if the data on them is older than 2 days.  That way I won't risk overwriting tapes when the changers don't change them.

    If Microsoft would just let you choose a retention period of 6 days all would be solved.

  • Please reference blogs.technet.com/.../how-to-expire-tape-recovery-points-in-dpm-2007.aspx for a more detailed explanation for the script and how to use it with Stand alone tape drives.

  • SMFV - I have experienced the same thing, at the cost of loosing data - I believe several updates have been posted on:

    blogs.technet.com/.../how-to-expire-tape-recovery-points-in-dpm-2007.aspx

  • script doesn't work in DPM 2010. ran it, no errors and nothing happened.

  • I made a copy of forcefree_tape.ps1 script that works on my DPM 2007 server ver. 3.0.7707.0, if anyone is interested.  bob@soilmoisture.com

  • Thanks for this

    @zack, only works in DPM 2010 for me when I run it on one slot at a time.

  • Scratch my last comment - it doesn't work with DPM2010 for me when I try to put the server, libarary name and tape slots in the command line.  If you run the script with no variables and answer the questions the script presents, it works fine.

  • Can anyone please help me with this script. It doesn't work for me.

    This script ask me question like

    1. slot

    2.libkey and how can i get the libkey please

    "Cannot bind argument to parameter 'libkey' because it is an empty string.

       + CategoryInfo          : InvalidData: (:) [DPMeraseTape.ps1], ParentContainsErrorRecordException

       + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,DPMeraseTape.ps1

  • Also trying to get this to run in a test environment on a Stand-Alone Drive. On DPM 2012 SP1 beta :)

  • Thank you.

  • DPMServername: everyone should know
    Libraryname:Everyone should know: If not see "Management" "Library"in DPM
    Slots: Slot-1 all other not working! No Space between it!!!