How to Find the Number of Snapshots per Volume using PowerShell

UPDATE: If you've got CDOT 8.2 take a look at this:
How to Count Snapshots in Clustered Data ONTAP in 8.2

1. Prerequisites

Note: If you’ve already got the Data ONTAP Powershell Toolkit installed, skip this section.

First, obtain the Data ONTAP Powershell Tookit (currently version 3.0) from:


Note: It requires you to be logged in to see the download link

Unpack the DataONTAP.msi and double-click to install. Then (assuming you have Windows 7/2008R2 or newer since these have WRM 2.0 and PowerShell 2.0 already) to verify it has installed correctly, set the ExecutionPolicy to enable the module to import, import the DataONTAP module, and see the cmdlets available; run the following in PowerShell:

Get-Module -ListAvailable
Set-ExecutionPolicy RemoteSigned
Import-Module DataONTAP
Get-NaHelp
Get-NcHelp

Note 1: You might need to reopen PowerShell after changing the ExecutionPolicy.
Note 2: NaHelp gives Data ONTAP 7-Mode cmdlets, NcHelp gives Clustered Data ONTAP cmdlets.

2A. How to Find Snapshot Count per Volume in Clustered Data ONTAP

## START COPYING HERE!
# Save as say snapcount.ps1 then run with PowerShell.
# It prompts for Cluster IP, credentials, and output filename.

Import-module DataOnTap

$controller = Read-host "IP of the CDOT Cluster"
$user = Read-host "Username for connection"

echo "connecting ..."

Connect-NcController $controller -credential $user
$vol = Get-NcVol

$filename = Read-host "Enter output filename"

foreach ($line in $vol){
 $volCount = (Get-NcSnapshot $line.name | measure).count
 $volName = $line.name
 echo "$volCount,$volName" >> $filename
}

notepad $filename

## STOP COPYING HERE!

2B. How to Find Snapshot Count per Volume in Data ONTAP 7-Mode

## START COPYING HERE!
# Save as say snapcount.ps1 then run with PowerShell.
# It prompts for Filer IP, credentials, and output filename.

Import-module DataOnTap

$controller = Read-host "IP of the Controller"
$user = Read-host "Username for connection"

echo "connecting ..."

Connect-NaController $controller -credential $user
$vol = Get-NaVol

$filename = Read-host "Enter output filename"

foreach ($line in $vol){
 $volCount = (Get-NaSnapshot $line.name | measure).count
 $volName = $line.name
 echo "$volCount,$volName" >> $filename
}

notepad $filename

## STOP COPYING HERE!

Credits

To my colleague Otm Sketar!

The Obligatory Image

Image: Data ONTAP PowerShell Toolkit packaged as an easy to install msi!

Comments