Scope

This post discusses methods to connect to multiple NetApp Storage Systems using the NetApp PowerShell Toolkit, and then execute commands against those storage systems

Background

OK, so you’ve setup the NetApp PowerShell Toolkit, and you can connect to a storage system and run some commands. But what if you have more than one storage system?

Conceptual overview

As with all things scripting, there’s many ways to achieve this, but here’s roughly what I’ll be blogging about below:

  1. Gettting a list of storage systems:
    1. Via Text File: Keep an easily-accessible text file up to date with all your storage systems
    2. By enumerating from Active Directory: Query AD to get a list of all your storage systems (providing they’re in AD!)
  2. Setup authentication details for all the storage systems
  3. Connect to the systems and run commands

Getting a list of storage systems

Text file method

This is the simplest and sweetest method, but doesn’t scale too well in a large organisation, so buyer beware 😉

Create a text file in an easily accessible location, such as your home directory or Desktop and populate it with a carriage-returned list of hostnames. For example:

cylon82
cylon814
</span>

Knowing where the text file is located, we can now setup the base for our PowerShell script:

Where's the list?
$ListLocation = "C:\Users\Phil\Desktop\filers.txt"
#Read the contents of the list into an array
$FilerList = Get-Content $ListLocation

Now, to see what’s inside the $FilerList array, just type:

echo $FilerList

You should now see a list of NetApp Storage Systems, like so:


Enumerate from Active Directory

Another way to get a more dynamic list of storage systems is to use an Active Directory lookup

In the example below, all the storage systems are called roughly the same thing. Many organisations have naming schemes, such as: na-site-number (for example, na-cbg-001). If you always call your storage systems the same thing, you can query AD and locate all your filers, like so:

import-module ActiveDirectory
 #what are we searching for?
 $FilerNameScheme = "na-site-*"
 #Let's query AD for systems with a name like $FilerNameScheme, and filter only Enabled accounts, and then only show the shortname for the host
 $FilerList = Get-ADComputer -Filter {(Name -like $FilerNameScheme) -and (Enabled -eq "True")} | Select -Expand Name

Now, to see what’s inside the $FilerList array, just type:

echo $FilerList

You should now see a list of NetApp Storage Systems!

Authenticating against multiple storage systems

OK great. Now that we have a list of storage systems, we can use the $FilerList array to authenticate to all the storage systems:

#Let's setup the login credentials we'll be using for the storage systems
 $authentication = Get-Credential
 
 foreach ($filer in $FilerList) { 
 
 #add authentication for this filer, using the credentials we just entered
 Add-NaCredential -Name $filer -Credential $authentication 
 
 }

At this point, you’ll be shown a list of all storage systems with authentication credentials stored.

For example:


Running Commands

Now that you’ve got a list of filers inside the $FilerList array and credentials queued up, you can start to run commands against them all using the simple template below. I’ll throw some examples in too, in case it helps:

#for each entry in the list, run these commands…
 foreach ($filer in $FilerList) { 
 
 #connect to the storage system
 Connect-NaController -Name $filer
 
 #Put your commands here, for example...
 #show system version
 get-nasystemversion | format-table
 #show volumes and aggrs
 Get-NaVolContainer ; Get-NaVol | format-table
 # show me the following options settings
 get-naoption cifs.smb2.enable cifs.smb2.client.enable cifs.tcp_window_size cifs.oplocks.enable
 

}

Putting it all together

Here’s an example of a full script which uses a text file for a list of filers, sets up login credentials, and then runs a few commands against each system.

#Where's the list?
$ListLocation = "C:\Users\Phil\Desktop\filers.txt"
#Read the contents of the list into an array
$FilerList = Get-Content $ListLocation

#Let's setup the login credentials we'll be using for the storage systems
$authentication = Get-Credential

foreach ($filer in $FilerList) { 
 
#add authentication for this filer, using the credentials we just entered
Add-NaCredential -Name $filer -Credential $authentication 
 
}

#for each entry in the list, run these commands...
foreach ($filer in $FilerList) { 
 
 #connect to the storage system
 Connect-NaController -Name $filer
 echo "Connecting to $filer"
 #show system version
 get-nasystemversion | format-table
 #show volumes and aggrs
 Get-NaVolContainer ; Get-NaVol | format-table
 # show me the following options settings
 get-naoption cifs.smb2.enable cifs.smb2.client.enable cifs.tcp_window_size cifs.oplocks.enable
 
}

And finally, here’s an example of the output you’d see:

How was that?

How was that? Let me know in the comments what you’re using it for. I’d love to know! 🙂