Tuesday, December 4, 2012

Powershell : How to delete Protection Group

Hi Guys,

I use these Powershell scripts to remove datasources from Protection Group:

(Data are retained for recovery purpose when using "-KeepDiskData" parameter. If you don't use "-KeepDiskData", Replica and Recovery points will be deleted)

1- CleanUp your DPM Server - Delete All Protection Groups

Connect-DpmServer $env:COMPUTERNAME
$PgList = @()
$PgList = Get-ProtectionGroup -DPMServerName $env:computername
foreach($Pg in $PgList){
write-host ""
Write-host "# ProtectionGroup Name " -ForegroundColor red -Nonewline
Write-host $Pg.FriendlyName -ForegroundColor green
$mpg = Get-ModifiableProtectionGroup $Pg
$dsList = @()
$dsList = Get-DataSource -ProtectionGroup $Pg
foreach($ds in $dsList){
write-host ("Remove data source ",$ds.Name)
Remove-ChildDataSource -ProtectionGroup $mpg -ChildDataSource $ds -keepDiskData
}
Set-ProtectionGroup $mpg
}
Disconnect-DpmServer $env:COMPUTERNAME


2- Delete a Protection Goup 

Connect-DpmServer $env:COMPUTERNAME
$StringSearch="YourStringSearch"
$PgList = @()
$pgList = Get-ProtectionGroup -DPMServerName $env:computername
where {($_.friendlyname) -match $StringSearch}
foreach($Pg in $PgList){
write-host ""
Write-host "# ProtectionGroup Name " -ForegroundColor red -Nonewline
Write-host $Pg.FriendlyName -ForegroundColor green
$mpg = Get-ModifiableProtectionGroup $Pg
$dsList = @()
$dsList = Get-DataSource -ProtectionGroup $Pg
foreach($ds in $dsList){
write-host ("Remove data source ",$ds.Name)
Remove-ChildDataSource -ProtectionGroup $mpg -ChildDataSource $ds -keepDiskData
}
Set-ProtectionGroup $mpg
}
Disconnect-DpmServer $env:COMPUTERNAME


Feel free to customize/use it.

No comments:

Post a Comment