Posts tagged ‘oneliner’

List all Volumes on all Controllers (7-Mode)

Volumes: The flexible storage containers of Data ONTAP. They can be resized, deduplicated, compressed, and even FlexCloned. But first, let’s just see which ones we have.

Several PowerShell one-liners will require a text file that I will refer to as NaList.txt. This file is simply a list of all the NetApp controllers in your environment, one per line:


PS C:\Scripts> Get-Content NaList.txt
netapp1
netapp2

Finally, the code:


Get-Content NaList.txt | ForEach-Object {Connect-NaController $_; Get-NaVol | Format-Table}

Now, the output:


Name                 Address           Ontapi   Version
----                 -------           ------   -------
netapp1              192.168.150.98    1.14     NetApp Release 7.3.6: Thu Jul  7 02:02:45 PDT 2011

Name                      State       TotalSize  Used  Available Dedupe  FilesUsed FilesTotal Aggregate
----                      -----       ---------  ----  --------- ------  --------- ---------- ---------
backup                    online        80.0 GB   24%    60.6 GB False         102         3M aggr0
vol0                      online         8.8 GB   15%     7.5 GB False         11k         7M aggr0

Name                 Address           Ontapi   Version
----                 -------           ------   -------
netapp2              192.168.150.99    1.14     NetApp Release 7.3.6: Thu Jul  7 02:02:45 PDT 2011

Name                      State       TotalSize  Used  Available Dedupe  FilesUsed FilesTotal Aggregate
----                      -----       ---------  ----  --------- ------  --------- ---------- ---------
vol0                      online         8.8 GB   15%     7.5 GB False         11k         7M aggr0

Now let’s make the code as short as possible by removing unnecessary spaces and utilizing PowerShell’s built in command aliases:


gc NaList.txt|ForEach{Connect-NaController $_;Get-NaVol|ft}

My attempt to explain the command in plain english: Get-Content (gc) reads the contents from NaList.txt and then pipes each line (controller) as an object to the ForEach-Object (foreach) command. Then for each object (controller) we issue Connect-NaController $_ ($_ represents the current object) and then issue the Get-NaVol command and finally pipe that output to the Format-Table (ft) function in order to get the nice easy to read tabular layout.

That’s it. Now you have a simple way to get a master list of every volume in your NetApp environment.

Questions? Comments? Do you think this could be done better? with less code? Let me know in the comments, please!