Microsoft Virtualization Discussions

delete snapshots - keep snapmirror

hi guys,

I am trying to delete all snapshots older than 2 days and that don't have @snapmir@ in them

I was trying this but 'whatif' tells me that the snapmirror snapshots will still be deleted

Get-NaVol  | Get-NaSnapshot | where-object {($_.Created -lt (Get-Date).AddDays(-2)) -and ($ -ne "@snapmir@*")} | remove-nasnapshot -whatif

here's an example of a snapmirror snapshot I want to keep:


what am I doing wrong?

thank you



Re: delete snapshots - keep snapmirror

Hi Joel,

I think you might want to use -notlike instead of -ne so the wildcard is evaluated.

I just did a quick test:

PS C:\> '@snapmir@{8DEC61ED-452A-4B21-8EDE-18503B0A2E37}' -ne "@snapmir@*"


PS C:\> '@snapmir@{8DEC61ED-452A-4B21-8EDE-18503B0A2E37}' -notlike "@snapmir@*"


I hope that helps!


View solution in original post

Re: delete snapshots - keep snapmirror

YES!!!  like a charm

Re: delete snapshots - keep snapmirror


'whatif' showed no issue but when I actually try to delete I am getting this:

VERBOSE: Deleting snapshot exchsnap__ex_08-30-2013_19.05.47__daily from volume exch2_1.

Remove-NaSnapshot : Could not find file 'C:\Users\admin\AppData\Local\Temp\omxngtox.dll'.

At line:1 char:244

+ Get-NaVol  | Get-NaSnapshot | where-object {($_.Created -lt (Get-Date).AddDays(-5)) -and ($ -notlike "@snapmir@

*") -and ($ -notlike "hourly*") -and ($ -notlike "nightly*") -and ($ -notlike "smvi_*")} | remove-nas

napshot <<<<  -confirm:$false -verbose

    + CategoryInfo          : InvalidOperation: ( [Remove-NaSnapshot], FileNotFoundException

    + FullyQualifiedErrorId : ApiException,DataONTAP.PowerShell.SDK.Cmdlets.Snapshot.RemoveNaSnapshot

here is the script:

PS C:\Windows\system32> Get-NaVol  | Get-NaSnapshot | where-object {($_.Created -lt (Get-Date).AddDays(-2)) -and ($_.nam

e -notlike "@snapmir@*") -and ($ -notlike "hourly*") -and ($ -notlike "nightly*") -and ($ -notlike "sm

vi_*")} | remove-nasnapshot -confirm:$false -verbose

any ideas?


Re: delete snapshots - keep snapmirror

Does anything from Thread Link : 12737 help?  It's possible a restart of the PowerShell session or host might resolve it.


Re: delete snapshots - keep snapmirror

yep, restarted the session and it went fine

Steven, is there something you don't know?

Cloud Volumes ONTAP
Review Banner
All Community Forums