Microsoft Virtualization Discussions

Deletion of Snapshots by pattern using Netapp Powershell ToolKit

andrew_stack
4,275 Views

Hi Folks,

I am trying to delete using powershell particular snapshots that have a common naming convention 'hotdb'.  I wish to avoid being asked if I'm sure and to basically delete the particular snapshots across many volumes en masse.  Here is what I tried on one particular volume and it did not work:

PS C:\Users\stacka1> Get-Ncvserver nac-rwc01-db01 |get-ncvol n01_cancdwd |get-ncsnapshot |select-string -pattern "hotdb"

cancdwd_1_20140603223105_hotdb

cancdwd_1_20140604223057_hotdb

cancdwd_1_20140605223102_hotdb

cancdwd_1_20140606223058_hotdb

cancdwd_1_20140607223036_hotdb

cancdwd_1_20140608223036_hotdb

cancdwd_1_20140609223046_hotdb

cancdwd_1_20140610223057_hotdb

cancdwd_1_20140611223100_hotdb

cancdwd_1_20140612223100_hotdb

cancdwd_1_20140613223059_hotdb

cancdwd_1_20140614223039_hotdb

cancdwd_1_20140615223038_hotdb

cancdwd_1_20140616223056_hotdb

cancdwd_1_20140617223102_hotdb

cancdwd_1_20140618223049_hotdb

PS C:\Users\stacka1> Get-Ncvserver nac-rwc01-db01 |get-ncvol n01_cancdwd |get-ncsnapshot |select-string -pattern "hotdb" |remove-ncsnapshot

Remove-NcSnapshot : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any o

f the parameters that take pipeline input.

Appreciate any help in advance...

Cheers,

Andrew

3 REPLIES 3

JGPSHNTAP
4,275 Views

I wouldn't use pattern in this way

You should use where-object

So, something like after your getting snapshot

| ? {$_.name -like "*hotdb*"} | remove-ncsnapshot -confirm:$False

-confirm:$false will not prompt you.. Make sure you test the command first with -whatif

andrew_stack
4,275 Views

Thanks!  That did the trick and it's quicker than any other means of deleting snaps.  Only thing is the command does not echo what it is doing so you really need to be careful...

Get-Ncvserver nac-rwc01-db01 |get-ncvol n01_cancdwd |get-ncsnapshot |? {$_.name -like "*hotdb*"} |remove-ncsnapshot -confirm:$False

JGPSHNTAP
4,275 Views

Well, there are two schools of thought.. You can do it this way, or feed the food into an array

Get-Ncvserver nac-rwc01-db01 |get-ncvol n01_cancdwd |get-ncsnapshot |? {$_.name -like "*hotdb*"} | % {

Write-host "Deleting Snapshot: " $_.name

remove-ncsnapshot $_.name -confirm:$False

}

Public