12 Replies Latest reply: Dec 21, 2012 12:19 PM by callowaydx RSS

Configuration info for a controller

callowaydx
Currently Being Moderated

Full disclosure, I'm fairly new to PowerShell but a big fan. I'm trying to learn more and more so that I can leverage it for my organization.

I'm developing a script that logs into each controller and gathers information that I specify. It takes that informaiton and add/appends it to a file based on the controller name and date/time then attaches those files and sends an email.

The script works up until I check for the multistore license and start checking for different info. Any suggestions? Maybe I need to clean up my script, too. Any and all help would be appreciated.

  • Re: Configuration info for a controller
    vinith
    Currently Being Moderated

    I wen through your script, and i found that the credential parameter is missing for Connect-NaController, you will need to specify credentials as below, i have highlighted the text which needs to be appended in black.

     

    ForEach ($Controller in $ControllerList)

    {

        #Admin account logon

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

        $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "administrator",$Password

        Connect-NaController $Controller -Credential $cred

     

    Also you can use custom hash tables to append all values to one place rather than using Add-Content to create reusable objects, please have a look at the link http://blogs.msdn.com/b/powershell/archive/2009/12/05/new-object-psobject-property-hashtable.aspx

    • Re: Configuration info for a controller
      callowaydx
      Currently Being Moderated

      Thank you for your help. I've fixed the credential portion (thanks for the catch) and I'm looking into hast tables.

       

      I'm having trouble with lines 102 - 126 of my script. The variable is not populating with info and I'm having difficulty getting the 'if' portion of my script to check if a value is true, the continue to run the script.

      Thoughts?

       

      #Check to see if the filer is licensed for multistore.

          #If it is, check for NFS/iSCSI related items.

          $NFSiSCSIVerify = Get-NaLicense -Name multistore

          if ($NFSViSCSIVerify.Licensed -eq "TRUE")

          {

          #Get vFiler info

          Get-NaVfiler | Out-String -Stream | Add-Content -Path $ControllerConfigFile

          $NFSiSCSIControllerList = Get-NaVfiler

         

          #Get NFS Export info running in memory

          Add-Content -Path $ControllerConfigFile -Value "

          NFS exports in memory

          "

          Invoke-NaSsh -Command "vfiler run * exportfs" | Out-String -Stream | Add-Content -Path $ControllerConfigFile

         

          #Run scripts against NFS/iSCSI controllers

          ForEach ($NFSiSCSIController in $NFSiSCSIControllerList)

              {

              #get NFS Exports info from the exports file

              Add-Content -Path $ControllerConfigFile -Value "

              NFS exports in the exports file -- Shoud match what is in memory...

              "

              Read-NaFile $("/vol/" + $NFSiSCSIController + "/etc/exports") | Out-String -Stream | Add-Content -Path $ControllerConfigFile

              }

         

          }

      • Re: Configuration info for a controller
        bsti@plex.com
        Currently Being Moderated

        Here is your issue:

         

        $NFSiSCSIVerify = Get-NaLicense -Name multistore

            if ($NFSViSCSIVerify.Licensed -eq "TRUE")

         

        You have an extra V in your second line. 

         

        Also, I'd avoid comparing a boolean value to a string. It works, but can be confusing.  I'd try something like this:

         

        if ($NFSiSCSIVerify.Licensed )

        or

        if ($NFSiSCSIVerify.Licensed -eq $true )

    • Re: Configuration info for a controller
      callowaydx
      Currently Being Moderated

      Looking over the hash table link you sent me and I'm not quite sure how to incorporate it...

       

      Would I hash this portion? Add-Content -Path $ControllerConfigFile

      I'm not sure how to use it as described in the link. And there also seems to be issues with ordering?

      • Re: Configuration info for a controller
        bsti@plex.com
        Currently Being Moderated

        I agree with Vinith in spirit in that it's better to export your data as objects, so that you can re-read them back into Powershell later and re-use them, but that might take quite a bit of rework on your part.  This is how you would use this concept:

         

        In our case, we have a script that does something very similar to what yours does.  Once per day, it grabs the options and values off of all controllers using Get-NaOption.  We then record that to a date stamped .xml file.  We then read in the previous days' file values and compare the two.  If there are differences, we get a report detailing what has changed.  Another useful function is we can read in the .xml files and quickly re-apply the option values.  Here is some example code:

         

        $options = Get-NaOption

         

        #  Export the options as object-oriented xml:

        $options | Export-CliXML -path c:\temp\options1.xml

         

        #  Import the same file back into a collection:

        $optionsFromFile = Import-CliXml -path c:\temp\options1.xml

         

        #  Reapply the options if I want (Be careful, this is dangerous):

        $optionsFromFile | % { Set-NaOption -OptionName $_.Name -OptionValue $_.Value }

         

        I'd probably never do this exact exercise, but it illustrates what you can do with object-oriented output and input.  XML works very nicely and the Export/Import-CliXML cmdlets make it very easy.  In your case, you are exporting quite a bit of unlike data, so I'm not sure this is practical with your approach.  I'd take a look and decide what works best for your application.

More Like This

  • Retrieving data ...