ONTAP Discussions

Highlighted

Netapp Powershell Output

Hi Guys, I need help with Powershell output i am getting.

I am able to get below output but i need below output to be arranged in format which i can put into CSV.

Is it possible?

 

PS D:\OCI\SOE_Compliance\System_Health> Invoke-ncssh -Command "system health subsystem show" | select Value | format-list
Keyboard-interactive authentication prompts from server:
End of keyboard-interactive prompts from server


Value : Subsystem Health
----------------- ------------------
SAS-connect ok
Environment ok
Memory ok
Service-Processor ok
Switch-Health ok
CIFS-NDO ok
Motherboard ok
IO ok
MetroCluster ok
MetroCluster_Node ok
FHM-Switch ok
FHM-Bridge ok
SAS-connect_Cluster ok
13 entries were displayed.

1 REPLY 1
Highlighted

Re: Netapp Powershell Output

Hi Raj,

 

I would not recommend using "invoke-ncssh". Consider using "invoke-ncsystemapi" instead which enables you to run an SSH command via HTTPS. Here is an example to connect to a cluster, run the system health subsystem show command and format the CLI results using comma delimited output:

 

Source Code:

 

Param(
   [Parameter(Mandatory = $True, HelpMessage = "The cluster to show the 'system health subsystem show' command for")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The credentials to connect to the cluster")]
   [System.Management.Automation.PSCredential]$Credentials
)
#'------------------------------------------------------------------------------
Function Format-SystemHealthSubsystem{
   Param(
      [Parameter(Mandatory = $True, HelpMessage = "The CLI output of the 'system health subsystem show' command")]
      [Array]$CLIOutput
   )
   [Array]$results  = @();
   [String]$header  = $($CLIOutput[0] -Replace '(^\s+|\s+$)', '' -Replace '\s+', ' ').ToString().Trim()
   [Array]$results += $header -replace ' ', ','
   For($i=2; ($i -le $CLIOutput.Count - 2); $i++){
      [String]$result  = $($CLIOutput[$i] -Replace '(^\s+|\s+$)', '' -Replace '\s+', ' ').ToString().Trim()
      [Array]$results += $result -replace ' ', ','
   }
   Return $results;
}#End Function
#'------------------------------------------------------------------------------
#'Import the NetApp DataONTAP PowerShell toolkit.
#'------------------------------------------------------------------------------
[String]$moduleName = "DataONTAP"
Try{
   Import-Module -Name $moduleName -ErrorAction Stop
   Write-Host "Imported module ""$moduleName"""
}Catch{
   Write-Warning -Message $("Failed importing module ""$moduleName"". Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Connect to the cluster.
#'------------------------------------------------------------------------------
Try{
   Connect-NcController -Name $cluster -HTTPS -Credential $Credentials -ErrorAction Stop | Out-Null
   Write-Host $("Connected to cluster ""$Cluster"" as user " + $Credentials.GetNetworkCredential().UserName)
}Catch{
   Write-Warning -Message $("Failed connecting to cluster ""$Cluster"". Error " + $_.Exception.Message)
   Break;
}
#'------------------------------------------------------------------------------
#'Invoke the SSH command via HTTPS.
#'------------------------------------------------------------------------------
Try{
   $command  = @("system", "health", "subsystem", "show")
   $api      = $("<system-cli><args><arg>" + ($command -join "</arg><arg>") + "</arg></args></system-cli>")
   $output   = Invoke-NcSystemApi -Request $api -ErrorAction Stop
   Write-Host $("Executed Command`: " + $([String]::Join(" ", $command)))
}Catch{
   Write-Warning -Message $("Failed Executing Command`: $command. Error " + $_.Exception.Message)
   Break;
}
If($output.results."cli-result-value" -eq 1){
   [Array]$CLIOutput = $output.results."cli-output".Trim().Split("`n")
   Format-SystemHealthSubsystem -CLIOutput $CLIOutput
}Else{
   Write-Warning -Message $("Failed Executing Command`: " + $([String]::Join(" ", $command)))
   Break;
}
#'------------------------------------------------------------------------------

 

Output:

 

PS C:\Scripts\PowerShell\Projects\SystemHealthSubSystemShow> $credentials = Get-Credential -Credential admin
PS C:\Scripts\PowerShell\Projects\SystemHealthSubSystemShow> .\SystemHealthSubSystemShow.ps1 -Cluster cluster1.testlab.local -Credentials $credentials
Imported module "DataONTAP"
Connected to cluster "cluster1.testlab.local" as user admin
Executed Command: system health subsystem show
Subsystem,Health
Switch-Health,ok
CIFS-NDO,ok
MetroCluster,ok
MetroCluster_Node,ok
FHM-Switch,ok
FHM-Bridge,ok

 

Hope that helps

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

Check out the KB!
Knowledge Base
All Community Forums