Data ONTAP PowerShell Toolkit - HOWTO: Work with Many Controllers

by Frequent Contributor on ‎2010-06-23 06:21 AM

In the Data ONTAP PowerShell Toolkit, you connect to a given controller using “connect-nacontroller”.  Once you have established a connection, the connection is transitive; you don’t need to specify –Controller in further cmdlets.  When it’s time to work with another controller, you simply connect to the next one and now this current connection is the default.  When you use “connect-nacontroller” a  NetApp.Ontapi.Filer.NaController object is returned.  Typically, you’d put that in a variable, then pass it in the –Controller parameter of future cmdlets:

$SIM2=connect-nacontroller SIM1

$SIM1=connect-nacontroller SIM2

Get-navol

Get-navol –Controller $SIM2

Would list all the volumes on SIM1 and then list all the volumes on SIM2.

That’s all fine and well, but what if you want to perform a set of repetitive actions on many controllers?  You can of course create a collection of NetApp.Ontapi.Filer.NaController objects:

[object[]]$Simulators=$null;foreach ($SIM in @("SIM1", "SIM2", "SIM3")) {$NewSIM=Connect-nacontroller $SIM;$Simulators=$Simulators+$NewSIM}

The above example creates a collection which contains NaController objects for three simulators, SIM1, SIM2, and SIM3.  Once you have you’re collection, you can pipe it to foreach-object and do something:

$Simulators | foreach-object -Process {get-navol -Controller $_}

Will display all the volumes on all three simulators.   In this somewhat simplistic example, I statically define an array of names.  What if I had a text file containing a list of controllers I wanted to take some action on, say set a few options?

[object[]]$SMControllers=$null;foreach ($SC in get-content SMControllers_list.txt) {$NewSC=Connect-nacontroller $SC;$SMControllers=$SMControllers+$NewSC}

$SMControllers | foreach-object -Process {set-naoption snapmirror.tunable_wsize.enable on -Controller $_;set-naoption snapmirror.window_size 6291456 -Controller $_}

In this example, I read a set of controller names from a text file, and use those names to populate my collection.  Once I’ve populated my collection, I pipe it to a foreach-object statement in which I set a couple of SnapMirror options.

Happy Scripting

J

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.