ONTAP-Buttons: Standard Code & GetNodeInfo

In the post Create SecureString File we wrote a tool to create a secure string file. Now we put that SecureString file to use, develop the standard code for "ONTAP-Buttons", and illustrate this with an example to Get Node Information for all nodes in a Clustered Data ONTAP cluster.

Batch File In ...\ONTAP-Buttons

The file GetNodeInfo.BAT has this content:

PowerShell.EXE .\PS\GetNodeInfo.PS1 -User admin -Cluster 192.168.168.200 -GetCredential

PowerShell Script in ...\ONTAP-Buttons\PS

The file GetNodeInfo.PS1 has the following content - any line that starts with <#S#> is standard content:

<#S#> Param(
<#S#>   [String]$Title = "Get Node Info", ## TITLE
<#S#>   [String]$User,
        [String]$Cluster,
<#S#>   [Switch]$SkipPressEnter,
<#S#>   [String]$SecurePasswordString,
<#S#>   [Switch]$GetCredential
<#S#> )
<#S#> FUNCTION Wr {Param([String]$Echo,[String]$Ink = "WHITE"); If($Echo){ Write-Host $Echo -ForegroundColor $Ink -NoNewLine } ELSE { Write-Host }}
<#S#> FUNCTION PressEnterToContinue{If(!$SkipPressEnter){Wr "Press ENTER to continue ..." CYAN; Read-Host}}
<#S#> If($SecurePasswordString){ $Password = $SecurePasswordString | ConvertTo-SecureString }
<#S#> elseif($GetCredential){
<#S#>   [String]$WhoAmi = WhoAmi
<#S#>   [String]$CredsFile = "PS\CREDS\" + $WhoAmi.Replace("\",".") + "." + $User.Replace("\",".") + ".CREDS"
<#S#>   If(!(Test-Path $CredsFile)){Wr "Unable to find credentials file!"; Wr; PressEnterToContinue; EXIT}
<#S#>   $Password = (Get-Content $CredsFile) | ConvertTo-SecureString}
<#S#> FUNCTION Load-DataOntapPSTK { If(Get-Module DataONTAP){ RETURN }
<#S#>   [Void](Import-Module DataONTAP -ErrorAction SilentlyContinue)
<#S#>   If(!(Get-Module DataONTAP)){Wr "Unable to load the DataONTAP PowerShell Toolkit - exiting!" RED; Wr; Wr; PressEnterToContinue; EXIT}
<#S#>   Wr "Loaded the Data ONTAP PowerShell Toolkit!" GREEN; Wr; Wr }
<#S#> FUNCTION Connect-ToCluster { Param([String]$ClusterName)
<#S#>   $Connect = Connect-NcController -Name $ClusterName -Credential $Credential -ErrorAction SilentlyContinue
<#S#>   If(!$Connect){Wr "Unable to connect to $ClusterName!" RED; Wr; Wr; PressEnterToContinue; EXIT}
<#S#>   Wr "Connected to $ClusterName" GREEN; Wr; Wr }
<#S#> Wr "+++++ $Title +++++" MAGENTA; Wr; Wr

Wr "Cluster Login User     : " CYAN; If($User){Wr $User; Wr}else{$User = Read-Host}
Wr "Cluster Login Password : " CYAN; If($Password){Wr "*****"; Wr}else{$Password = Read-Host -AsSecureString}
Wr "Cluster                : " CYAN; If($Cluster){Wr $Cluster; Wr}else{$Cluster = Read-Host}; Wr

<#S#> $Credential = New-Object System.Management.Automation.PsCredential($User,$Password)

[Void](Connect-ToCluster $Cluster)
$Nodes = Get-NcNode; $NodeCount = $Nodes.Count; $i = 1
FUNCTION WrData {
  Param([System.Object]$ObjectIn,[String]$PropertyName,[String]$HealthyResult,[Int]$Pad = 28)
  Wr (("$PropertyName".PadRight($Pad).Substring(0,$Pad)) + ": ") CYAN
  [String]$Property = $ObjectIn.$PropertyName
  If($HealthyResult){If($Property -eq $HealthyResult){Wr $Property GREEN}else{Wr $Property RED}}
  elseif($Property){Wr $Property}; Wr
}
$Nodes | Foreach{
  Wr (">>> Node " + [String]$i + " of " + [String]$NodeCount) MAGENTA; Wr
  WrData $_ "Node"
  WrData $_ "CpuBusytime"
  WrData $_ "CpuFirmwareRelease"
  WrData $_ "EnvFailedFanCount" "0"
  WrData $_ "EnvFailedFanMessage" "There are no failed fans."
  WrData $_ "EnvFailedPowerSupplyCount" "0"
  WrData $_ "EnvFailedPowerSupplyMessage" "There are no failed power supplies."
  WrData $_ "EnvOverTemperature" "False"
  WrData $_ "IsAllFlashOptimized"
  WrData $_ "IsDiffSvcs"
  WrData $_ "IsEpsilonNode"
  WrData $_ "IsNodeClusterEligible" "True"
  WrData $_ "IsNodeHealthy" "True"
  WrData $_ "MaximumAggregateSize"
  WrData $_ "MaximumNumberOfVolumes"
  WrData $_ "MaximumVolumeSize"
  WrData $_ "NodeAssetTag"
  WrData $_ "NodeLocation"
  WrData $_ "NodeModel"
  WrData $_ "NodeNvramId"
  WrData $_ "NodeOwner"
  WrData $_ "NodeSerialNumber"
  WrData $_ "NodeStorageConfiguration"
  WrData $_ "NodeSystemId"
  WrData $_ "NodeUptime"
  WrData $_ "NodeUuid"
  WrData $_ "NodeVendor"
  WrData $_ "NvramBatteryStatus" "battery_ok"
  WrData $_ "ProductVersion"
  WrData $_ "VmhostInfo"
  WrData $_ "VmSystemDisks"
  Wr; PressEnterToContinue; $i ++
}

<#S#> Wr "THE END!" MAGENTA; Wr; Wr; PressEnterToContinue; EXIT

GetNodeInfo in Action

Double-click GetNodeInfo.BAT which has already been specified with Cluster User, Cluster Management IP Address, and we have already generated the credential file -

Image: GetNodeInfo.BAT
- and, bam, node info is displayed!

Image: GetNodeInfo.BAT and GetNodeInfo.PS1 in action (with credentials generated by CreateSecureStringFile.BAT)

Comments

  1. Really helpful information, thanks for sharing this!
    I used to share your posts with my friend who works on some task connected with virtual data rooms and he said that was worth implementing.

    ReplyDelete
  2. Best description ever..if you want to know about bit coin and getnode you can come in this link Getnode

    ReplyDelete
  3. Really helpful information, thanks for sharing this!
    led signs in pakistan

    ReplyDelete

Post a comment