Microsoft Virtualization Discussions

Remove Snapshot by name

JGPSHNTAP

In our environment we sometimes get stale SME snapshots that start with {. 

So here is a little powershell script that will loop through all the filers and remove it.

[Code]

### Mail "constants"

      $sendMailAs    = "x"

   $recipients    = "X"

       $subjectLine = "GUID LOG"

       $mailMessage = "GUID Report  The Attached Snapshots have been removed from the filers."

       $smtpServer = "X"

       $priority = "high"

### File Constants

    $date = (get-date).toString('dd-MMM-yyyy_h-mm-ss')

    $ext = ".log"

    $outfile = "Exchange_GUID__" + $date + $ext

    $delim = "`t"

Import-Module DataONTAP

$hostfile = "exchange.txt"

gc $hostFile |% {

    $nacontroller = Connect-NaController $_

    Get-NaVol | Get-NaSnapshot -SnapName "{*" | select TargetName,Name,Created,Total,CumulativeTotal | ft @{Expression={$nacontroller};Label="Filer name";Width=20},@{Expression={$_.TargetName};Label="Volume";Width=40},@{Expression={$_.Name};Label="Name";Width=40},@{Expression={$_.Created.ToShortDateString()};Label="Created";Width=12},@{Expression={ConvertTo-FormattedNumber $_.Total DataSize "0.0"};Label="Total";Width=10},@{Expression={ConvertTo-FormattedNumber $_.CumulativeTotal DataSize "0.0"};Label="Cumulative";Width=10} | Out-File -filepath $outfile -append

    get-navol | get-nasnapshot -snapname "{*" | where-object {$_.busy -like "*false*"} | remove-nasnapshot -confirm:$false

}

## Send Email

Send-MailMessage -To $recipients -From $sendMailAs -Attachments $outfile -Subject $subjectLine -Body $mailMessage -Priority $priority -SmtpServer $smtpServer

#####

[/code]

Now, i'm not sure its the best way to do this, but it works.    I wanted to ensure we weren't trying to delete busy snaps so I through in $_.busy -like "*false*".   I tried -eq "false" but it wouldn't return anything which was confusing to me .

Now remember i'm very new to powershell so any criticism is welcome.  I didn't know a good way to log in one line and then delete in another so, I had to run the cmdlet again.  Any suggestions for imporvement are welcome.

1 REPLY 1

cknight

where-object { $_.busy -eq $false }

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public