Comparing Aggregate Options Across All Aggregates in a Cluster

The following script will collect all the aggregate options of all the aggregates in a cluster, and output into a CSV, so you can compare. Simply run in PowerShell as PS>


.\Compare-AggrOptions.ps1


An example of the CSV output is below:

Image: AggrOptions.CSV Output

The Script

Copy into a text editor and save as Compare-AggrOptions.ps1.


Param(
  [Parameter(Mandatory=$true)][String]$Cluster,
  [String]$ClusterUserName,
  [String]$ClusterPassword
)

## GENERIC: DISPLAY FUNCTION
Function Wr{Param([String]$Echo = "",[String]$Ink = "WHITE"); Write-Host $Echo -ForegroundColor $Ink}

## GENERIC: LOAD THE DATA ONTAP PSTK
If(!(Get-Module DataONTAP)){ [Void](Import-Module DataONTAP -ErrorAction SilentlyContinue) }
If(Get-Module DataONTAP){ Wr "Loaded DataONTAP PSTK" GREEN }
else{ Wr "Failed to load DataONTAP PSTK!" RED; EXIT }

## GENERIC: CONNECT TO CLUSTER
If($ClusterUserName -and $ClusterPassword){
  $SecPass = $ClusterPassword | ConvertTo-SecureString -asPlainText -Force
  $Cred = New-Object System.Management.Automation.PsCredential($ClusterUserName,$SecPass)
  [Void](Connect-NcController $Cluster -Credential $Cred -ErrorAction SilentlyContinue)
} else {
  If(!(Get-NcCredential $Cluster)){
    $Cred = New-Object System.Management.Automation.PsCredential($(Read-Host "ClusterUserName"),$(Read-Host "ClusterPassword" -AsSecureString))
    [Void](Add-NcCredential -Controller $Cluster -Credential $Cred)
  }
  [Void](Connect-NcController $Cluster -ErrorAction SilentlyContinue)
}
If($Global:CurrentNcController){ Wr "Connected to $Cluster" GREEN}
else{ Wr "Failed to connnect to $Cluster!" RED; EXIT }

## CREATE CSV OF AGGREGATES AND AGGREGATE OPTIONS
$AggrAttr = get-ncaggr -Template
[System.Array]$Aggrs = (Get-NcAggr -Attributes $AggrAttr).Name
$OptionNames = (Get-NcAggrOption $Aggrs[0]).Name

[System.Array]$CSV = @()
$Aggrs | Foreach {
  $aggrOpts = Get-NcAggrOption $_
  $O = New-Object PSObject
  Add-Member -InputObject $O -MemberType NoteProperty -Name "Aggregate" -Value $_
  Foreach ($Option in $OptionNames){
    [String]$Value = ($aggrOpts | Where{$_.Name -eq $Option}).Value
    Add-Member -InputObject $O -MemberType NoteProperty -Name $Option -Value $Value
  }
  $CSV += $O
}

$CSV | Where-Object {$_} | Export-CSV -Path "AggrOptions.CSV" -NoTypeInformation


Note: This was tested against CDOT 8.3.2.

Comments