Subscribe

NetApp Powershell Shutdown Script

I have two NA filers that I'm writing a shutdown script to be kicked off by APC PowerChute. Really simple, I just need to Invoke-NaSsh and halt the system. I'm having a problem actually connecting to the filer, though. It appears that the generated PSCredential object (as per "get-help Connect-NaController -examples", example 4) isn't working. When manually invoking the Get-Credential function, the Connect-NaController process runs just fine. Even allocating a separate $cred variable, and outputting the Get-Credential result works. However, the given syntax from the example throws the following error.

Connect-NaController : Could not connect to x.x.x.x on port 80 for protocol HTTP.

At line:1 char:21

+ Connect-NaController <<<<  x.x.x.x -Credential $cred

    + CategoryInfo          : InvalidResult: (10.20.4.15:NaController) [Connect-NaController], NaConnectionException

    + FullyQualifiedErrorId : HttpConnectionFailed,DataONTAP.PowerShell.SDK.ConnectNaController

Here's the actual script in question:

# Power off NetApp (poweroffnetapp.ps1)

#

# This script is intended to simply shut down a NetApp filer. It is intended

# to run after all other services and systems dependent upon the SAN have

# already halted.

#

# Created By: Ian Young

#

# Variables:  $filers - A comma separate list of filers for this script to

#                                                            execute upon.

#

#

# Usage: ./poweroffnetapp.ps1

#        Intended to be ran in the command section of the APC Powerchute Network

#        Shutdown program before the shutdown sequence has started.

#

#################################################################################

 

Import-Module DataONTAP

 

$user = "root"

$password = ConvertTo-SecureString "password" -AsPlainText -Force

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password

$filer1 = "x.x.x.x"

$filer2 = "x.x.x.x"

   

Write-Host "Shutting down Filer 1"

Connect-NaController $filer1 -Credential $cred

Invoke-NaSsh -Command 'halt -t 0'

 

Write-Host "Shutting down Filer 2"

Connect-NaController $filer2 -Credential $cred

Invoke-NaSsh -Command 'halt -t 0'

It's an absurdly simple script that is meant to run after our SAN-reliant hosts have been shut down. I'm sure I'm missing something completely rudimentary here, but I've never written anything using the DataONTAP Powershell kit, so I'm at a loss. Thanks for any help or advice you can offer!

Re: NetApp Powershell Shutdown Script

You can configure connect-nacontroller how you want to connect to the controller, I believe the default is HTTPS (secureadmin setup ssl).

From a powershell command line issue a Import-Module DataONTAP command, then do a connect-nacontroller filername -cred username -HTTP, then see what happens.

Options

Connect-NaController [-Name] <String> [-Port <UInt16>] [-Credential <PSCredential>] [-HTTPS] [-HTTP] [-RPC] [-Transient] [-Vfiler <String>] [-Timeout <Int32>] [<CommonParameters>]

       

DESCRIPTION

    Establish a connection to a Data ONTAP storage controller.  Unless 'Transient' is true, this connection is saved in the global variable CurrentNaController.  All other cmdlets in the Data ONTAP PowerShell Toolkit utilize this global variable if their 'Controller' parameter is not explicitly provided.

   

    Connections are established using RPC by default.  To use HTTPS (with automatic fallback to HTTP), supply the Credential parameter (see examples) or save credentials in the Toolk it credentials cache.

   

    Use the RPC/HTTP/HTTPS parameters to limit connections to a specific protocol.

Re: NetApp Powershell Shutdown Script

It's defaulting to HTTP for some reason, but we've also tried with HTTPS & RPC. Both also result in an error. Here is the output of each.

Connect-NaController : RPC Error: The RPC server is unavailable. Code 0x6BA.

At line:1 char:21

+ Connect-NaController <<<<  $filer1 -Credential $cred -RPC

    + CategoryInfo          : InvalidResult: (x.x.x.x:NaController) [Connect-NaController], EAPITRANSMISSION

    + FullyQualifiedErrorId : RpcConnectionFailed,DataONTAP.PowerShell.SDK.ConnectNaController

Connect-NaController : Incorrect credentials for x.x.x.x

At line:1 char:21

+ Connect-NaController <<<< x.x.x.x -Credential $cred -HTTPS

    + CategoryInfo          : InvalidResult: (x.x.x.x:NaController) [Connect-NaController], NaAuthException

    + FullyQualifiedErrorId : HttpConnectionFailed,DataONTAP.PowerShell.SDK.ConnectNaController

Now, I'm not entirely sure why HTTPS claims to have incorrect credentials. This is the exact same object setup. It seems like the correct object isn't being produced. Because, as I mentioned before, when manually invoking Get-Credential and running, everything works, and I get a connection object on $CurrentNaController.

Re: NetApp Powershell Shutdown Script

Does nobody have any idea what's going on here? I would think that the premise of the script, to connect to the controller and run one halt command, would be simple. What's happening?

Re: NetApp Powershell Shutdown Script

Hmm.. This isn't something I can "test" b/c I can't halt a filer.

Have you tried to run the commands line by line

Also you should create an array of your controllers

$hosts = @("filer1","filer2")

$user = "root"

$password = ConvertTo-SecureString "password" -AsPlainText -Force

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user,$password

$hosts | % {

$filer = $_

WRite-host "Connecting to Controller: " $Filer

     $C = connect-nacontroller $filer -https -credential $cred

write-host "Halting Filer..... "

Invoke-NaSsh -Command 'halt -t 0'

}

Re: NetApp Powershell Shutdown Script

I got the same problem. Solved by doing :

     $UserName="root"

     $Password="netapp"

     $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$UserName",(ConvertTo-SecureString $Password -AsPlainText -Force)

Note the double quotes for the username .. that solved the problem for me.

Re: NetApp Powershell Shutdown Script

Your original code works for me without any changes.  I don't have any issues with it, so that's strange.

Here are my questions:

What version of the Powershell toolkit are you running?

Do you have a firewall between the station running the script and the controller?  That would explain the RPC issue.  If so, try this test again from a machine inside the firewall.

In your testing where you used -HTTPS, it says you used invalid credentials.  Is there any chance the password or username got goofed?  That's a fairly specific error message.