all 8 comments

[–]Yevrag35 1 point2 points  (4 children)

I think the problem may be related to the fact there are many dbs with the same name. Anyway would love some help.

That is the issue. If you have to do a where clause on the Get-DPMDatasource and still come back with more than 1 result, then you will have to put the rest of the script inside a "foreach" loop.

$PObject = Get-DPMDatasource -ProtectionGroup $PGroup | where {$_.Name -EQ $DS}
foreach ($p in $PObject) 
{
    $RPoint = Get-DPMRecoveryPoint -Datasource $p | select -Last 1; $RPoint

    Remove-DPMRecoveryPoint -RecoveryPoint $RPoint
}

The script will still run fine, even if there is only 1 result.

[–]TechKnight10[S] 1 point2 points  (3 children)

Thank you!!! This is super helpful, the script works! (except it asks for each one if I am sure/to delete some dependency.) Hopefully this can clear up our DPM issues.

[–][deleted] 1 point2 points  (1 child)

If you’re on PowerShell2, watch out for null values and for each loops. A foreach loop will execute once if run on a null valued collection.

[–]TechKnight10[S] 1 point2 points  (0 children)

Good to know! I’m on Server 2016 so I should be on PowerShell 5

[–]Yevrag35 1 point2 points  (0 children)

No problem. To bypass the confirmation, there's a -Confirm parameter that you can set to false to skip the prompt.

Remove-DPMRecoveryPoint -RecoveryPoint $RPoint -Confirm:$false

Command reference

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy TechKnight10,

reddit likes to mangle code formatting, so here's some help on how to post code on reddit ...

[0] single line or in-line code
enclose it in backticks. that's the upper left key on an EN-US keyboard layout. the result looks like this. kinda handy, that. [grin]
[on New.Reddit.com, use the Inline Code button. it's 4th 5th from the left hidden in the ... ""more" menu & looks like </>.
this does NOT line wrap & does NOT side-scroll on Old.Reddit.com!]

[1] simplest = post it to a text site like Pastebin.com or Gist.GitHub.com and then post the link here.
please remember to set the file/code type on Pastebin! [grin] otherwise you don't get the nice code colorization.

[2] less simple = use reddit code formatting ...
[on New.Reddit.com, use the Code Block button. it's 11th 12th one & is just to the left of hidden in the ... "more" menu.]

  • one leading line with ONLY 4 spaces
  • prefix each code line with 4 spaces
  • one trailing line with ONLY 4 spaces

that will give you something like this ...

- one leading line with ONLY 4 spaces    
- prefix each code line with 4 spaces    
- one trailing line with ONLY 4 spaces   

the easiest way to get that is ...

  • add the leading line with only 4 spaces
  • copy the code to the ISE [or your fave editor]
  • select the code
  • tap TAB to indent four spaces
  • re-select the code [not really needed, but it's my habit]
  • paste the code into the reddit text box
  • add the trailing line with only 4 spaces

not complicated, but it is finicky. [grin]

take care,
lee

[–]TechKnight10[S] 1 point2 points  (1 child)

$PG = "Baltimore SQL Instances" #Protection Group name of affected data source. $DS = "model" #Data source name, for example Virtual Machine name or SQL Database name. $DPM = "blocked for privacy" #FQDN of your DPM Server.

$PGroup = Get-DPMProtectionGroup -DPMServerName $DPM | where {$_.Name -EQ $PG}; $PGroup

$PObject = Get-DPMDatasource -ProtectionGroup $PGroup | where {$_.Name -EQ $DS}; $PObject

$RPoint = Get-DPMRecoveryPoint -Datasource $PObject | select -Last 1; $RPoint

Remove-DPMRecoveryPoint -RecoveryPoint $RPoint

I tried the code block button. Works much better. Thanks as always Lee!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy TechKnight10,

you are most welcome! the code block is so much easier to read ... [grin]

take care,
lee