Subscribe

Netapp Options Check Powershell

Hi All

Posting for some help again, I have a modified script that checks all the options of a master filer and checks target filers and show the differences, but Im struggling to get the excel to align properly for each of the options, does anyone know how to fix the formatting or is there an easier way to check a set of netapp filers against master filer through a script in perl or any other language any ideas welcome. The script is below and kinda works but half way down the options seem to get mixed up and misallgned not sure what Im doing wrong to be honest.

Ive tested it with mixed filer models and also with models that are all the same but it still doesnt work.

I just need to keep all the filers options the same like our master filer.

Any ideas I would be greatful

import-module DataONTAP

$workingController = "master_server"
$targetControllers= @("server1","server2")
$User = "xxx"
$Pass = "xxx"

$WCPass  = ConvertTo-SecureString $Pass -AsPlainText –Force
$Wcred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$WCPass
$TCPass  = ConvertTo-SecureString $Pass -AsPlainText –Force
$Tcred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$WCPass
$workops=new-object system.collections.arraylist
ForEach ($Controller in $TargetControllers){Connect-NaController $Controller}

$suppress = $Targops = get-naoption
Write-host "------------------------------------------------"

$excel=new-object -comobject excel.application
$excel.Visible=$true
$workbooks=$excel.workbooks.add()
$worksheet=$workbooks.worksheets.item(1)

$worksheet.cells.item(1,1)="Option Name"
$worksheet.cells.item(1,1).font.bold=$true
$worksheet.cells.item(1,1).font.size=22
$worksheet.cells.item(2,1)="Controller Name"
$worksheet.cells.item(2,1).font.bold=$true
$worksheet.cells.item(2,1).font.size=22
$worksheet.cells.item(1,2)="Master FAS"
$worksheet.cells.item(1,2).font.bold=$true
$worksheet.cells.item(1,2).font.size=22
$worksheet.cells.item(2,2)=$WorkingController
$cellR=3
foreach($Controller in $TargetControllers)

{          Connect-NaController $Controller
          $Workops.add( (get-naoption  ) )
           $worksheet.cells.item(1,$cellr)="Target FAS"
           $worksheet.cells.item(1,$cellr).font.bold=$true
           $worksheet.cells.item(1,$cellr).font.size=22
           $worksheet.cells.item(2,$cellr++)=$controller
}
$worksheet.cells.item(1,$cellr)="Command to fix"


Write-host "------------------------------------------------"
$coun=2
foreach ($workop in $workops)
{     $coun=$coun+1
      $line=2
      $founditem=$false
      foreach ($item in $workop)
      {      $workname=$item.name
            $workval =$item.value
            foreach($titem in $targops)
            {     if ($titem.name -eq $item.name)
                  {      $line=$line+1
                        $foundvalue=$true
                        $worksheet.cells.item($line,1)=$titem.name
                        $worksheet.cells.item($line,2)=$titem.value
                        $worksheet.cells.item($line,$coun)=$item.value
                        write-host "   "$item.name"="$item.value    
                        if ($titem.value -ne $item.value)
                        {      write-host "   "$item.name"="$item.value" -Values Mismatch ="$titem.value
                              $worksheet.cells.item($line,$cellr)=("set-naoption"+$titem.name+" "+$item.value)
                              write-host "        To fix this issue, command is as follows;"
                              write-host "           set-naoption"$titem.name""$item.value
                        }
                  }
            }
      }
}
$workdoc=$worksheet.UsedRange
$workdoc.EntireColumn.Autofit() | out-null

Re: Netapp Options Check Powershell

You might consider trying to isolate the part of the script that you are having the problem with.  I'm not very familiar with excel, and that is a lot of code with confusing variable names (item, $item, $titem) to try to visually debug.

At the very least you could indicate what type of problem you are seeing or what the output is.

Help us help you!

Re: Netapp Options Check Powershell

Hi

For example if you look at row 25 and 26 the 1440 value should be in row 26, the excel output (attached) seems to go out of sync later on in script output, rows 1-15 are fine and 19-29 have gone out of synch.

Any help would be appreciated. Its like the excel comes out of synch, you can run the script against a set of filers and see what I mean

Thanks

Re: Netapp Options Check Powershell

I think you're problem is that you have different sets of options on your controllers.  I'd use the "Get-NaOption -Hashtable" switch so you can simply lookup the option you need (whether it exists or not).  Here's a really quick example to demonstrate the concept:

$masterController = Connect-NaController 10.61.169.28

$targetController = Connect-NaController 10.61.169.29

$masterOptions = Get-NaOption -Hashtable -Controller $masterController

$targetOptions = Get-NaOption -Hashtable -Controller $targetController

$allKeys = $masterOptions.Keys + $targetOptions.Keys | sort | Get-Unique

foreach ($key in $allKeys)

{

    Write-Host $key, $masterOptions[$key], $targetOptions[$key]

}

Hope that helps!

Re: Netapp Options Check Powershell

Here is a quick and dirty way of comparing the options:

$controller1= "yourfiler1"

$controller2= "yourfiler2"

Connect-NaController $controller1

$optiona= get-naoption

Connect-NaController $controller2

$optionb= get-naoption

Compare-Object $optiona $optionb

Re: Netapp Options Check Powershell

Thanks for all these ideas, ive tried the script where all the filers are the same so it ruled out there being different options/releases/models (they are the same to P release) ill still try a hashtable but think its the excel, the script actually detects if the targets differ from the master its just the excel is misalligned half way down the output. I would like to have it in an excel or text file so we can quickly see the differences for a number of filers and then I send it out to the admins via email. It was originally adopted from this script which only compared the autosupport options https://communities.netapp.com/docs/DOC-14848.

I liked the way the output was so I changed this script to run for all options, not sure if I need to make another adjustment to accomodate the script for all options I changed

This

$suppress = $Targops = get-naoption autosupport.*

to this $suppress = $Targops = get-naoption

So it would capture all of the options not just the autosupport options but not sure if something else needs changing Ive gone through it lots of times but cant see it.

It seems to work well if you only have the autosupport* in the script

Thanks