Get latest snapshot

Hi all,

I need help to create a PS script that runs on multiple filers and gets the latest snapshots on the volumes.

Then, email this information.

Can anyone help?


Re: Get latest snapshot

Hey Seffy,

Can you try this

save the below to a .ps1 file, make sure that you enter your controller names in filernames.txt, the current script asks the user for credentials everytime it reads a new controller name in filernames.txt

$filerlist = Get-Content "c:\filernames.txt"


foreach ($filer in $filerlist)


Connect-NaController -Name $filer -Credential (Get-credential)

$voldetails = Get-NaVol

foreach ($vol in $voldetails)


$snapshotdetails = Get-Nasnapshot -TargetName $vol | Sort-Object -Descending created | select -First 1

        $volinformation = New-Object -TypeName psobject -Property @{

            'VolumeName'    = $vol.Name;

            'VolumeLatestSnapshotName' = $snapshotdetails.Name;

            'VolumeLatestSnapshotCreatedDate' = $snapshotdetails.created;

            'VolumeLatestSnapshotTotal(MB)' = ($snapshotdetails.Total)/1mb

            'VolumeLatestSnapshotCumulative(MB)' = ($snapshotdetails.CumulativeTotal)/1mb



            $volinfoarraysnap += $volinformation



$volinfoarraysnap | Export-Csv "c:\volsnapinfo.csv"

If you have a same user name and password for all your controllers you can use the below scriptlet in your code.

$ControllerPassword = ConvertTo-SecureString -String 'netapp1!' -AsPlainText -force

$credential = New-Object System.Management.Automation.PsCredential("vsadmin",$ControllerPassword)

$test = Connect-NaController -Name $control -Credential $credential

Re: Get latest snapshot

Hi Vinith,

Thank you for your reply.

the script works great, but is it possible to have it run on the volumes and show only volumes that haven't been snapshots in the last 48 hours?

What i mean is: have it run on all filers then get all volumes snapshots and if a volume doesn't have a snapshot in the last 48 hours, show in CSV.


Re: Get latest snapshot

can you replace the variable $snapshotdetails with the below and see if it helps.

$snapshotdetails = Get-Nasnapshot -TargetName $vol | Sort-Object -Descending created | select name,created,total,cumulativetotal,@{Name="AccessTime"; Expression = {([datetime]"1/1/1970").AddSeconds($_.AccessTime).ToLocalTime()}} | where-object {$_.AccessTime -lt (Get-Date).Addhours(-48)} | select -First 1

you can also use (get-date).Adddays(-2) to find snapshots older than two days (48 hours)

Message was edited by: Vinith Menon

Re: Get latest snapshot

Hi Vihith,

tried it and the report comes back empty.

What i want to achieve is the report to shows only volumes with snapshot older then 48 hours and not show volumes with newer snap shots.

What I mean is if the latest snap shot is older than 48 hours, show it on the CSV.