Microsoft Virtualization Discussions

connecting to multiple filers using powershell

diwakar
11,832 Views

Hello All,

 

               I am working with NetApp for few years but I never had the chance to work on Powershell before. I had been trying to get started with NetApp Powershell module for few days. I am able to connect to filers individually and run few cmdlets. But if I am having issues in connecting to multiple filers at once and list system info by using foreach loop in my profile. But surprisingly the same profile is working fine at times. By saying working , I am not getting any output but it runs without throwing any errors. You can see the loop I am talking about below:

 

foreach ($filer in $allfilers){
#connect to the storage system
Connect-NaController $filer -Credential $authentication
echo "Connecting to $filer"

echo "--------------"$filer"-------------"
get-nasysteminfo
}

 

In the above loop, should I give a pause or anything in order to get the filer info?  But I am getting errors at most of the times which are shown below:

 

Connect-NaController : Object reference not set to an instance of an object.
At D:\Data\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:20 char:21
+ Connect-NaController <<<< $filer -Credential $authentication
+ CategoryInfo : InvalidResult: (filer1:NaController) [Connect-NaController], NullReferenceException
+ FullyQualifiedErrorId : HttpConnectionFailed,DataONTAP.PowerShell.SDK.ConnectNaController

 

Get-NaSystemInfo : Value in $global:CurrentNaController is not of type NetApp.Ontapi.Filer.NaController
At D:\Data\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:23 char:17
+ get-nasysteminfo <<<<
+ CategoryInfo : InvalidArgument: (:smileyhappy: [Get-NaSystemInfo], ArgumentException
+ FullyQualifiedErrorId : ControllerNotSpecified,DataONTAP.PowerShell.SDK.Cmdlets.System.GetNaSystemInfo

Connect-NaController : Object reference not set to an instance of an object.
At D:\Data\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:20 char:21
+ Connect-NaController <<<< $filer -Credential $authentication
+ CategoryInfo : InvalidResult: (filer2:NaController) [Connect-NaController], NullReferenceException
+ FullyQualifiedErrorId : HttpConnectionFailed,DataONTAP.PowerShell.SDK.ConnectNaController

 

Any information in this regard would be really helpfull. Thank you very much in advance.

 

Thanks,

MD.

7 REPLIES 7

mbeattie
11,822 Views

Hi MD,

 

Here is an "example" for you including some error checking.

 

[String]$fileSpec = "C:\Scripts\controllers.txt"
[String]$username = "root"
[System.Security.SecureString]$password = Read-Host "Please enter the password for user ""$userName""" -AsSecureString
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $password
$controllers = Get-Content -Path $fileSpec
Import-Module DataONTAP
ForEach($controller In $controllers){
   Do{

      If($controller -eq ""){

         Break;

      }
      Try{
         Connect-NaController –Name $controller –Credential $credentials –HTTPS –ErrorAction Stop
         Write-Host “Connected to controller “”$controller”””
      }Catch{
         $errorMessage = $error[0].Exception.Message
         Write-Warning "Failed connecting to Controller ""$controller"". $errorMessage"
         Break;
      }
      Try{
         Get-NaSystemInfo -ErrorAction Stop
      }Catch{
         $errorMessage = $error[0].Exception.Message
         Write-Warning "Failed enumerating System Information for Controller ""$controller"". $errorMessage"
         Break;
      }
   }Until($True)
}

 

Where "controllers.txt" contains a list of your controller names (either in hostname, ip address or FQDN format) one controller name per line in the text file.

Note: This "assumes" that your password to connect to each controller is consistent (hence it only prompts for credentials once).

 

Hope that helps

 

/matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

diwakar
11,773 Views

Hello Matt,

 

              Thank you very much for taking time in replying me.  When I implemented your code exactly the way you sent it (except modifying where my text document with filer list is present) it failed with the following error for the same number of times as there are number of filers in the filers.txt :

 

WARNING: Failed connecting to Controller "". Cannot bind argument to parameter 'Name' because it is null.

 

I modified $controller to $controllerName in the below part as $controllerName was used in the rest of the script. 

.

.

.

ForEach($controller In $controllers){
   Do{

      If($controller -eq ""){

         Break;

      }

..

.

.

When I implemented the above changes in your code it is giving me this error:

 

PS C:\WINDOWS\system32> & $PROFILE
Please enter the password for user "root": ***********

WARNING: Failed connecting to Controller "filer1". The requested name is valid, but no data of the requested type was found.

 

Is there anything I am missing?

 

Thanks,

MD.

 

 

bbjholcomb
11,749 Views

I encrypt the password first:

$password = ConvertTo-SecureString -string $encrypted

 

Then just before connecting to each system put this:

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$userid",$password
Connect-NcController -Name $clname -Credential $cred -HTTPS –ErrorAction Stop

 

(This is for cDOT but change it tConnect-NaController)

mbeattie
11,703 Views

Hi MD,

 

There was a typo in the code (the variable $controller was spelt $controllerName).

Please re-run the posted code and let me know if you have any issues

 

/matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

diwakar
11,687 Views

Hello Matt,

 

                 As I mentioned in my previous email I changed the $controllers to $controllerName. And I had the error I mentioned before. But when I opened the powershell to implement the changes you recomended, it worked this time even before me making the changes.  Does the logging into the filer fail if the filer is busy? because I observed that the same profile throws some errors which would work at times. 

 

Thanks,

Madhu.

 

mbeattie
11,680 Views

Hi Madhu,

 

I've not encountered the error you recieved: "The requested name is valid, but no data of the requested type was found". I would suggest checking DNS configuration to ensure that A & PTR records exists for the controller hostnames. Alternately you could connect to the controller by IP Address instead of hostname (update each line in your text file from hostname to it's corresponding IP Address). I've not seen connections fail due to high load however you can specify an additional timeout parameter to the "connect-nacontroller" cmdlet however the default (60 seconds) should be sufficent to connect to the controller. See "Get-Help Connect-NaController -full | more"

 

    -Timeout <Int32>
        Connection timeout in milliseconds.  Only applies to HTTP/HTTPS connections.

        Required?                    false
        Position?                    named
        Default value                60000
        Accept pipeline input?       false
        Accept wildcard characters?  false

 

Also you might consider adding an ICMP test within the Do loop to test network connectivity before attempting to connect. EG

 

#'------------------------------------------------------------------------------
#'Ensure the storage controller is online and responding to ICMP requests.
#'------------------------------------------------------------------------------
If(-Not(Test-Connection -ComputerName $Controller -count 1)){
   Write-Warning "The Storage Controller ""$Controller"" did not respond to an ICMP request"
   Break;
}

 

/matt

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

NazeerMohammed
7,039 Views

Hello Mat,

 

I am trying to connect and getting disk fauure information for 7 mode and cDOT system without using NetApp PS toolkit. do you have any script or guidline to write script.

 

Regards

Nazeer  

Public