Wednesday, 23 March 2016

Get 7-Mode LUNs Super CSV

Essentially, I just wanted to get the LUN Geometry Size and Max Resize Size, for LUNs being migrated from a 7-Mode system, and then decided, “why not create a LUNs Super CSV” - then I can sort and filter to my heart’s content in Excel. The CSV contains all LUNs and their Get-NaLun, Get-NaLunGeometry, and Get-NaLunMap info; with my bonus column of GeometryMaxGrowthMultiplier (Max Resize Size / Size). Save the script as say Get-NaLUNsSuperCSV.ps1, and run as in the screen shot below:


The Script

########################
## Get-NaLUNsSuperCSV ##
########################

## ===== GENERIC FUNCTIONS ===== ##
Function Wr{
  Param([String]$Echo,[String]$Ink = "WHITE")
  If($Echo){ Write-Host $Echo -ForegroundColor $Ink -NoNewLine }else{ Write-Host }
}
Function Get-Prompt{
  While($TRUE){
    Wr $Args CYAN; $ReadHost = Read-Host
    If($ReadHost){ RETURN $ReadHost }
  }
}

## ===== TITLE ===== ##
[String]$Title = "Get-NaLUNsSuperCSV"
Wr;Wr "+++++ $Title +++++" MAGENTA;Wr;Wr

## ===== CHECK THE PSTK ===== ##
If(!(Get-Module DataONTAP)){ [Void](Import-Module DataONTAP -ErrorAction SilentlyContinue) }
If(!(Get-Module DataONTAP)){ Wr "Failed to load DataONTAP PSTK!" RED;Wr;Wr;EXIT }
else{ Wr "Loaded DataONTAP PSTK." GREEN;Wr;Wr }

## ===== PROMPT FOR CONTROLLER/GET CREDENTIALS/ TEST CONNECTION ===== ##
[String]$NaController = Get-Prompt "Enter NetApp 7-Mode Controller IP/DNS:"
If(!(Get-NaCredential $NaController)){
  [String]$UserName = Get-Prompt "Enter Username:"
  Wr "Enter Password:" CYAN; $Password = Read-Host -AsSecureString
  $Credentials = New-Object System.Management.Automation.PsCredential($Username,$Password)
  [Void](Add-NcCredential -Name $NaController -Credential $Credentials)
}
If(!(Get-NaCredential $NaController)){ Wr "Failed to Get-NaCredential $NaController!" RED;Wr;Wr;EXIT }
else{ Wr ("Using credential " + ((Get-NaCredential $NaController).Credential.UserName) + " for $NaController.") GREEN;Wr }
If(!(Connect-NaController $NaController -ErrorAction SilentlyContinue)){ Wr "Failed to connect to $NaController! Verify> options httpd.admin.enable on" RED;Wr;Wr;EXIT }
else{ Wr "Connected to $NaController." GREEN;Wr;Wr }

## ===== GET LUN PROPERTIES ===== ##
Wr "Getting LUN Properties " CYAN
[System.Array]$NaLunProperties = "Path","Size","SizeUsed","MultiprotocolType","Online","Mapped","Thin","Comment","Alignment","BackingSnapshot","BlockSize","CloneBackingSnapshot","DeviceId","IsSpaceReservationEnabled","PrefixSize","ReadOnly","SerialNumber","ShareState","Staging","SuffixSize","Uuid"
[System.Array]$NaLunGeometryProperties = "BytesPerSector","Cylinders","MaxResizeSize","SectorsPerTrack","TracksPerCylinder"
[System.Array]$NaLunMapProperties = "InitiatorGroupAluaEnabled","InitiatorGroupName","InitiatorGroupOsType","InitiatorGroupPortsetName","InitiatorGroupThrottleBorrow","InitiatorGroupThrottleReserve","InitiatorGroupType","InitiatorGroupUsePartner","InitiatorGroupUuid","InitiatorGroupVsaEnabled","Initiators","LunId"

[System.Array]$LunsCollection = @()
Get-NaLun | Foreach{
  Wr "." CYAN
  $Object = New-Object PSObject
  Foreach($Property in $NaLunProperties){      
    Add-Member -InputObject $Object -MemberType NoteProperty -Name $Property -Value $_.$Property
  }
  $LunGeometry = $_ | Get-NaLunGeometry
  Foreach($Property in $NaLunGeometryProperties){
    Add-Member -InputObject $Object -MemberType NoteProperty -Name ("Geometry" + $Property) -Value $LunGeometry.$Property
  }
  [Double]$MaxGrowth = $LunGeometry.MaxResizeSize / $LunGeometry.Size
  Add-Member -InputObject $Object -MemberType NoteProperty -Name ("GeometryMaxGrowthMultiplier") -Value $MaxGrowth
  $LunMap = $_ | Get-NaLunMap
  Foreach($Property in $NaLunMapProperties){
    Add-Member -InputObject $Object -MemberType NoteProperty -Name $Property -Value $LunMap.$Property
  }
  $LunsCollection += $Object
};Wr;Wr
Wr "Saving LUN properties to $Title.CSV" CYAN;Wr;Wr
$LunsCollection | Export-CSV "$Title.CSV" -NoType


No comments:

Post a Comment