WFA has a custom cmdlet called "Invoke-WfaClusterCli", which is
doing the same thing, assuming you wanted to SSH to a Netapp Cluster ofcourse :)
I posted the code below, just for reference. Obviously in WFA you can just call it, as it's embedded in the WFAWrapper module.
###################################################### function Invoke-WfaClusterCli { param( [parameter(Mandatory=$true)] [string]$CliCommand, [parameter(Mandatory=$false)] [NetApp.Ontapi.Filer.C.NcController]$Controller, [parameter(Mandatory=$false)] [string]$PrivilegeMode ) Get-WFALogger -Info -message "Executing cli command: $CliCommand" $cliXmlRequest = "<system-cli><args>" $arrCliArgs = $CliCommand.Split(" "); foreach($arg in $arrCliArgs) { if($arg -and $arg -ne "") { $cliXmlRequest+="<arg>" + $arg + "</arg>" } } $cliXmlRequest += "</args>" if($PrivilegeMode) { $cliXmlRequest += "<priv>$PrivilegeMode</priv>" } $cliXmlRequest += "</system-cli>" try { if($Controller) { if($Controller.Vserver) { throw "Cannot execute system-cli api in a Vserver context" } $xmlResult = Invoke-NcSystemApi -Request $cliXmlRequest -Controller $Controller -ErrorAction Stop } else { # if $global:CurrentNaController is not populated (session not connected to any filer) an exception is thrown like # original Netapp POSH Toolkit Cmdlet if($global:CurrentNcController.Vserver) { throw "Cannot execute system-cli api in a Vserver context" } $xmlResult = Invoke-NcSystemApi -Request $cliXmlRequest -ErrorAction Stop } # Examining the cli execution's return code from the storage system if($xmlResult.results."status" -ne "passed") { throw "Cli XML request failed to pass" } # if xml request passed -> examining result value flag elseif($xmlResult.results."cli-result-value" -ne 1) { throw $xmlResult.results."cli-output" } Get-WFALogger -Info -message "Cli command completed successfully" Get-WFALogger -Info -message $("Cli output: " + $xmlResult.results."cli-output") return $xmlResult.results."cli-output" } catch { Get-WFALogger -Error -message $_.Exception.Message throw $_.Exception } }
Cool, thx for that hint. Had also some commands to do and converted it manually into XML for ZAPI use. Thumbs up.
ReplyDelete