32 Replies Latest reply: May 1, 2013 11:30 AM by JSHACHER11 RSS

first script

JSHACHER11
Currently Being Moderated

Hi guys,

 

I started playing with powershell this week - I've tried to run the following but getting this:

 

"the size of the volume is DataONTAP.Types.Volume.SizeInfo"

 

the script is:

 

Import-Module dataontap

$filername = Read-Host 'What is the filer hostname?'

$name = Read-Host 'What is your username?'

Connect-NaController -Name $filername -Credential $name

$volname = Read-Host 'What is the volume name?'

$volsize = Get-NaVolSize -Name $volname

Write-Host "the size of the volume is:" $volsize

 

my debugger is saying that my problem is in this line:

 

$volsize = Get-NaVolSize -Name $volname

 

Thank you

  • Re: first script
    spence
    Currently Being Moderated

    Make sure you set your execution policy to unrestricted.

     

    Is your storage controller joined to the domain?  If so, then is your domain account (logged on with) a member of the storage controllers administrator's group?

         If yes, then:

     

    Import-Module dataontap

    $filername = Read-Host "What is the filer hostname?"

    Connect-NaController -Name $filername | out-null

    $volname = Read-Host "What is the volume name (case sensitive)?"

    $volsize = Get-NaVolSize $volname

    Write-Host "The size of the volume is:"$volsize.volumesize

     

    If no, then:

    Import-Module dataontap

    $filername = Read-Host "What is the filer hostname?"

    Connect-NaController -Name $filername -Credential (get-credential) | out-null

    $volname = Read-Host "What is the volume name (case sensitive)?"

    $volsize = Get-NaVolSize $volname

    Write-Host "The size of the volume is:"$volsize.volumesize

    • Re: first script
      JSHACHER11
      Currently Being Moderated

      no go

       

      Thanks though

      • Re: first script
        cscott
        Currently Being Moderated

        I am late to the discussion, but this is working for me:

         

        Import-Module dataontap

         

        $filername = Read-Host 'What is the filer hostname?'

         

        $name = Read-Host 'What is your username?'

         

        Connect-NaController -Name $filername -Credential $name

         

        $volname = Read-Host 'What is the volume name?'

         

        $volsize = Get-NaVolSize -Name $volname

         

        Write-Host "the size of the volume is:" ($volsize).volumesize

         

         

        What is the error that the debugger is throwing out?

         

        -Scott

        • Re: first script
          JSHACHER11
          Currently Being Moderated

          Scott,

           

          I am getting this:

           

          "the size of the volume is DataONTAP.Types.Volume.SizeInfo"

           

          The only difference between my script and yours is this:

           

          mine:

           

          Write-Host "the size of the volume is:" $volsize

           

          yours:

           

          Write-Host "the size of the volume is:" ($volsize).volumesize

           

          (is that my issue?)

           

          I would have to try that again with your line

           

          I'll let you know

           

          Thanks

          • Re: first script
            cscott
            Currently Being Moderated

            Yep, you need to call the property(volumesize) of the object ($volsize).  Otherwise it simply returns the object type, not the usable information of the object.

             

            -Scott

            • Re: first script
              JSHACHER11
              Currently Being Moderated

              sweet

               

              I'll try that and let you know

               

              Thanks

               

              Joel

            • Re: first script
              danekantner
              Currently Being Moderated

              I have to wonder--is there any reason NetApp implements the ToString method on this object to output the object type name as a string instead of the volumesize integer itself?

              • Re: first script
                cscott
                Currently Being Moderated

                I cannot say on authority, but powershell is object oriented, therefore in this context the request is for an object that is being called back into a variable. Now $volsize is an object, to get that object's information, you have to reference the property .  The property of variable/object  $volsize is the output, and in order to conform to proper syntax and compatibility it should be required to call (object).property.  Otherwise you end up with no idea of how one output should be called in reference to another.  By that what I mean is what object only has one property and therefore will output a single property as int/str/arr, etc?  You could not expect to write anything with any certainty because the rule could change for every single output, now multiply that by every vendor doing it their own way, gets to be a mess very quickly.

                 

                If you run get-navolsize -name vol0, you get a default output which is a header, separator, and the output integer.

                 

                -Scot

        • Re: first script
          JSHACHER11
          Currently Being Moderated

          Works!

           

          Thanks Scott

           

          Can we take it a step further?

           

          - How do I list all volumes (just volume names) and Read-Host "pick a volume from the list to show its size"

          - If the input volume name does not exist, can we display a message >> "volume doe not exist, try again"

           

          Cheers

          • Re: first script
            cscott
            Currently Being Moderated

            Joel, I am in training, but I have attached a script here that does the same sort of thing for finding CIFS shares and setting the browse/nobrowse option.  I have added some notes to it, but I should be able to work with it to do this for volumes sometime next week(should be pretty simple).

             

            Also for the write-output, that comes out in bytes, an easy format option is to use write-output ($volsize).volumesize |convertto-formattednumber -type datasize

             

            -Scott

             

            Message was edited by: Scott Chubb for spelling/grammar

            • Re: first script
              JSHACHER11
              Currently Being Moderated

              images.jpg

              • Re: first script
                cscott
                Currently Being Moderated

                Here ya go! Since the user selects by number, there shouldn't be mistakes in vol name.  The script retains the check to make sure the user is entering a number, but now returns a human readable formatted vol size. (Got bored at lunch)

                 

                -Scott

                • Re: first script
                  JSHACHER11
                  Currently Being Moderated

                  Scott, what does this line do?  >>   $volList = @($volList)

                  • Re: first script
                    cscott
                    Currently Being Moderated

                    Dynamically builds an array so that we can build a menu for any number of volumes.  '@' indicates an array, so for each volume found by get-navol, we put them into an array, then use that to build the menu and further on to identify which object we want to see the output on.

                     

                    FYI, for clarity - Powershell 2.0 has some issues building single item arrays.  I have to use $volist = @($volist) for the times that I end up with only a single entry in the array. Powershell 2.0 will reset it to a string unless you explicitly call it again as an array, Powershell 3.0 is supposed to fix this, but I am not ready to move to 3.0 yet.

                     

                    -Scott

                     

                    Message was edited by: Scott Chubb for clarity and additional information.

                    • Re: first script
                      JSHACHER11
                      Currently Being Moderated

                      Scott, the script worked with the first filer (netapp03 - # 2) I picked but when I run it again against another filer ( # 0 or 1) it gives me this:

                       

                       

                      PS.jpg

                       

                      I know for sure that netapp01 and netapp02 exist and they use the same credentials

                       

                       

                      Here is the script

                       

                       

                      ===========================================

                       

                      Import-Module dataontap

                       

                       

                       

                      #You will need to change PASSWORD to use the login credentials.  This required httpd.admin.enable to be set to on

                      #You will need to change myNode for each filer you want to add.  You may need to add/remove nodes for your environment

                      #

                       

                      #Ensure the user enters a number

                      Function isNumeric ($x) {

                      $x2 = 0

                      $isNum = [System.Int32]::TryParse($x,[ref]$x2)

                      return $isnum

                      }

                       

                      #Build the list of shares by system and set the option to hide/show the share

                      Function listFilerShares {

                       

                      #secure login creations

                          $myNetAppUser = "root"

                          $myNetAppArrayPass = "<change_with_your_password>"

                          $myNetAppPass = ConvertTo-SecureString $myNetAppArrayPass -AsPlainText -Force

                          $myNetappCred = New-Object -TypeName system.Management.Automation.PSCredential -ArgumentList $myNetAppUser,$myNetAppPass

                       

                      connect-nacontroller $mySelectedNode -Credential $myNetAppCred

                       

                      #get a list of shares and build an array

                      $volList = Get-NaVol |ForEach-Object {write-output $_.Name}

                      $volList = @($volList)

                       

                      $i = 0

                      while ($i -le ($volList.length - 1 ))

                      {

                      Write-Host "$i.) "$volList[$i]

                      $i++

                      }

                      [int]$volMenu = Read-Host "select a volume by number"

                      while (-not(isNumeric $volMenu))

                      {

                      [int]$volMenu = Read-Host "Error in entry : select a volume by number"

                      }

                      while (-not($volMenu -le ($volList.length - 1 )))

                      {

                      $volMenu = Read-Host "Error in entry : select a volume by number"

                      }

                      $volSize = get-navolsize -Name $volList[$volMenu]

                      Write-Output ($volSize).volumesize | ConvertTo-FormattedNumber -Type datasize

                      }

                       

                       

                      #Build a menu of filers to select from

                      Write-Host "Select a filer by number"

                      write-host "0.) netapp01"

                      write-host "1.) netapp02"

                      write-host "2.) netapp03"

                      Write-Host " "

                       

                      $mySelectedNode = Read-Host "Select 0-2"

                      while (-not(isNumeric $mySelectedNode))

                      {

                      $mySelectedNode = Read-Host "Select 0-2"

                      }

                      while (-not($mySelectedNode -le 2))

                      {

                      $mySelectedNode = Read-Host "Select 0-2"

                      }

                       

                      switch ($mySelectedNode)

                      {

                           0 {

                           $mySelectedNode = "netapp01"

                           }

                           1 {

                           $mySelectedNode = "netapp02"

                           }

                           2 {

                           $mySelectedNode = "netapp03"

                           }

                      }

                       

                      listFilerShares

                       

                      =====================================

                       

                       

                      Thanks

                       

                      Joel

                      • Re: first script
                        JSHACHER11
                        Currently Being Moderated

                        2 more questions:

                         

                        1. How do I list failed disks?

                        2. How do I show Snapmirror Lag of (only) more than 24 hours?

                         

                        I've tried this:

                         

                        (Get-NaSnapmirror).LagTimeTS | {$_.Hours -gt 24}    

                         

                        Cheers

                        • Re: first script
                          cscott
                          Currently Being Moderated

                          I already have a script for checking my snapmirror lags, I have attached it here. (It appears that this is an older version that was not complete, I will post the finished version when I get back home on Monday.)  The formatting section is something I have found on the communities, so I cannot take credit for the output being formatted so well.

                           

                          As to the disks, I don't have anything that checks for it, but I am assuming that it will be something along the lines of:

                           

                          get-nadisk | foreach-object  | write-output $_.Name {where-object $_.Status -eq "failed" }.

                           

                          "$_" means take whatever comes out of the foreach-object and use it as an object, in this case each disk is made a variable as it is found by the for loop.

                           

                          Training is over around Noon eastern and I can use the simulator on my laptop to see how badly I have mangled that disk command.

                           

                          -Scott

                           

                          Message was edited by: Scott Chubb - removed script, which was not the correct version.

                          • Re: first script
                            cscott
                            Currently Being Moderated

                            Joel,

                                 Sorry got busy and forgot about this.  I did some minor editing as there was a problem with the formatting.  This is the touchiest script I have....the formatting has to have everything just so, and I have never set down long enough to learn what the difference is in how this formatting is invoked.

                             

                            -Scott

                      • Re: first script
                        cscott
                        Currently Being Moderated

                        So for this let's do something basic:

                        replace this:

                        $myNetAppUser,$myNetAppPass

                         

                        connect-nacontroller $mySelectedNode -Credential $myNetAppCred

                         

                        with this:

                         

                        $myNetAppUser,$myNetAppPass

                        write-output $mySelectedNode

                        connect-nacontroller -Name $mySelectedNode -Credential $myNetAppCred

                         

                        This will allow us to make sure that we are getting the node name from the switch statement properly.  If we see the node we expect to see, we have an issue outside the script in most cases.

                         

                        -Scott

  • Re: first script
    vinith
    Currently Being Moderated

    Hello,

     

    In the below scriptlet you are connecting to the controller only with username, you are not entering the password

     

    $name = Read-Host 'What is your username?'
    Connect-NaController -Name $filername -Credential $name
    

     

     

    Try with the below method

     

    $name = Read-Host 'What is your username?'
    $password = Read-Host 'What is your Password?'
    $ControllerPassword = ConvertTo-SecureString -String $password -AsPlainText -force
    $credential = New-Object System.Management.Automation.PsCredential($name,$ControllerPassword)
    Connect-NaController -Name $filername -Credential $credential
    
  • Re: first script
    JGPSHNTAP
    Currently Being Moderated

    Joel -

     

    Do a quick search for a blog post i submitted that will dump out all the filers and volumes sizes etc... You can re-use the code for your liking.

     

    I see from your flurry of posts that you are just getting going on PS which is great.  Start with the getting started powerpoint presentation as well.

     

    Also, i'm noticing you are starting everything with import-module.  I believe in powershell 3.0 all modules are loaded. you can check that by launching powershell and typing get-module

    If you are using 2.x you need to add import-module dataontap to your profile.ps1 file. 

  • Re: first script
    JGPSHNTAP
    Currently Being Moderated

    Here, give this a shot

     

    get-navol vol0 | get-navolsize | select @{E={convertto-formattednumber $_.volumesize datasize "0.00"};N="Vol size"}

More Like This

  • Retrieving data ...