Statistics

  • Entries (5)
  • Comments (0)

Recover Share using PowerShell Script 

Posted by David Wednesday, January 13, 2010 6:34:32 PM
Rate this Content 0 Votes

 

View the article DPM - Using PowerShell to Recover Shares for full details of this script.

---------

param([string] $DPMServerName, $ProtectionGroup, $Datasource, $ShareName, $DestinationServer, $DestinationLocation)
 
 
function Usage()
{
  write-host
  write-host "Usage::"
  write-host "Recover-Share.ps1 -DPMServerName [DPMServerName] -ProtectionGroup [ProtectionGroupName] -Datasource [DatasourceName] -ShareName [ShareName] -DestinationServer [DestinationServer] -DestinationLocation [DestinationLocation]"
  write-host
  write-host "Run 'Recover-Share.ps1 -detailed' for detailed help"
  write-host
  write-host
}
if(("-?","-help") -contains $args[0])
{
  Usage
  exit 0
}
if(("-detailed") -contains $args[0])
{
  write-host
  write-host "Detailed Help :  Use this script to recover a share"
  write-host
  write-host "Example: Recover-Share.ps1 -DPMServerName 'DPM01.lab.com' -ProtectionGroup 'Shares' -Datasource 'C:\' -ShareName 'NewShare' -DestinationServer 'FILE01.lab.com' -DestinationLocation 'C:\ShareRecovery'"
  write-host
  exit 0
}
if((Get-PSSnapIn -Name "Microsoft.DataProtectionManager.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
  Add-PSSnapIn "Microsoft.DataProtectionManager.PowerShell"
}
if(!$DPMServerName)
{
  $DPMServerName = read-host "DPMServerName::"
}
$DpmServer = Connect-DPMServer $DPMServerName
if (!$DpmServer)
{
  write-Error "Failed To Connect To DPM Server::$DPMServerName"
  exit 1
}
if(!$ProtectionGroup)
{
   $ProtectionGroup = read-host "ProtectionGroupName::"
}
$pg = Get-ProtectionGroup -DPMServerName $DPMServerName | where { $_.FriendlyName -eq $ProtectionGroup }
if (!$pg)
{
  write-Error "Failed To Find A Protection Group Named::$ProtectionGroup"
  exit 1
}
if(!$Datasource)
{
  $Datasource = read-host "DataSourceName::"
}
$ds = Get-Datasource $pg | where { $_.Name -eq $Datasource }
if (!$pg)
{
  write-Error "Datasource Not Found With Name::$Datasource"
  exit 1
}
$rp = (Get-RecoveryPoint $ds | sort -Property RepresentedPointInTIme -Descending)[0]
if(!$rp)
{
  Write-Error "No Recovery Points Found For Datasource::$Datasource"
  exit 1
}
if(!$ShareName)
{
  $ShareName = read-host "ShareName::"
}
$ri = Get-RecoverableItem -RecoveryPointForShares $rp | where { $_.UserFriendlyName -eq $ShareName }
if(!$ri)
{
  Write-Error "No Recoverable Item Found For Share::$ShareName"
  exit 1
}
if(!$DestinationServer)
{
  $DestinationServer = read-host "DestinationServer::"
}
if(!$DestinationLocation)
{
  $DestinationLocation = read-host "DestinationLocation::"
}
$ro = New-RecoveryOption -TargetServer $DestinationServer -RecoveryLocation copytofolder -FileSystem -AlternateLocation $DestinationLocation -OverwriteType overwrite -RestoreSecurity -RecoveryType Restore        
$Recovery = Recover-RecoverableItem -RecoverableItem $ri -RecoveryOption $ro
if($Recovery)
{
  Write-Host "Running recovery for $ShareName from $($rp.RepresentedPointInTime)"
  While(!$Recovery.HasCompleted)
    {
      Write-Host "." -NoNewLine
      sleep 3
    }
  Write-Host "`nJob status: $($Recovery.Status)"
}
else
{
  Write-Error "`nCould not find a recovery item on disk for $ShareName"
}
Disconnect-DPMServer
Share This Using Popular Bookmarking Services
Copyright 2010 SCDPMOnline.org
You must sign in to this site to post comments.

Site Map | Printable View | © 2008 - 2010 SCDPM Online

Locations of visitors to this page

Powered by mojoPortal | HTML 5 | CSS | Design by styleshout