<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Posh-ssh output to array in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Posh-ssh-output-to-array/m-p/2863035#M102855</link>
    <description>&lt;P&gt;Hi, i'm using Posh SSH to check some config settings&amp;nbsp;&lt;/P&gt;&lt;P&gt;The specific command i'm interested in is&amp;nbsp;&lt;STRONG&gt;Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Output from&amp;nbsp;&lt;STRONG&gt;Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"&lt;/STRONG&gt; is&lt;/P&gt;&lt;P&gt;Host : myServerNameHere.mycomp.com&lt;BR /&gt;Output : {Tx_ring_size : 4096}&lt;BR /&gt;ExitStatus : 0&lt;/P&gt;&lt;P&gt;Creating a Posh-SSH Session and running the command works as expected.&lt;/P&gt;&lt;P&gt;$sshUsername = 'admin'&lt;BR /&gt;$password = 'notThePassword!'&lt;BR /&gt;$sshPassword = $password | ConvertTo-SecureString -AsPlainText -Force&lt;BR /&gt;$sshPassword.MakeReadOnly()&lt;BR /&gt;$sshCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $sshUsername,$sshPassword&lt;BR /&gt;$sshCredential = Get-Credential -Credential $sshCred&lt;/P&gt;&lt;P&gt;$sshSession = New-SSHSession -ComputerName 'myServerNameHere.mycomp.com' -Credential $sshCredential -AcceptKey:$true&lt;BR /&gt;if ($sshSession.Connected -like "True") {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$Tx_ring_size = Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"&lt;BR /&gt;Write-Host "Tx_ring_size is: " -NoNewline&lt;BR /&gt;(($Tx_ring_size.Output -split ':')[1]).Trim("{","}")&lt;BR /&gt;&lt;BR /&gt;$Rx_ring_size = Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Rx_ring_size"&lt;BR /&gt;Write-Host "Rx_ring_size is: " -NoNewline&lt;BR /&gt;(($Rx_ring_size.Output) -split ':')[1]&lt;/P&gt;&lt;P&gt;Write-Host "Disconnecting ssh session to myServerNameHere.mycomp.com "&lt;BR /&gt;Remove-SSHSession -SessionId $sshSession.SessionId | Out-Null&lt;BR /&gt;Write-Host -ForegroundColor DarkGray "`n------------------------------------------------------------------`n"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Output to the console is as expected&lt;/P&gt;&lt;P&gt;Tx_ring_size is: 4096&lt;BR /&gt;Rx_ring_size is: 4096&lt;BR /&gt;Disconnecting ssh session to myServerNameHere.mycomp.com&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a report for a large number of Servers by entering the details into an array and outputting the contents of the array&lt;/P&gt;&lt;P&gt;$ServerNameArray = @()&lt;/P&gt;&lt;P&gt;$resultsArray = @()&lt;/P&gt;&lt;P&gt;$downloadsDir = "$HOME\Downloads"&lt;/P&gt;&lt;P&gt;foreach ($item in $ServerNameArray){&lt;/P&gt;&lt;P&gt;$resultsProperty = [ordered] @{&lt;BR /&gt;'Server_FQDN'=$item.FQDN&lt;BR /&gt;'Server_IP' = $item.IP&lt;/P&gt;&lt;P&gt;$sshUsername = 'admin'&lt;BR /&gt;$password = 'notThePassword!'&lt;BR /&gt;$sshPassword = $password | ConvertTo-SecureString -AsPlainText -Force&lt;BR /&gt;$sshPassword.MakeReadOnly()&lt;BR /&gt;$sshCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $sshUsername,$sshPassword&lt;BR /&gt;$sshCredential = Get-Credential -Credential $sshCred&lt;/P&gt;&lt;P&gt;$sshSession = New-SSHSession -ComputerName 'myServerNameHere.mycomp.com' -Credential $sshCredential -AcceptKey:$true&lt;BR /&gt;if ($sshSession.Connected -like "True") {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$Tx_ring_size = Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"&lt;BR /&gt;Write-Host "Tx_ring_size is: " -NoNewline&lt;BR /&gt;(($Tx_ring_size.Output -split ':')[1]).Trim("{","}")&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$resultsProperty.Add("Tx_ring_size",(($Tx_ring_size.Output -split ':')[1]).Trim("{","}"))&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;$Rx_ring_size = Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Rx_ring_size"&lt;BR /&gt;Write-Host "Rx_ring_size is: " -NoNewline&lt;BR /&gt;(($Rx_ring_size.Output) -split ':')[1]&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$resultsProperty.Add("Rx_ring_size",(($Rx_ring_size.Output -split ':')[1]).Trim("{","}"))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Write-Host "Disconnecting ssh session to myServerNameHere.mycomp.com "&lt;BR /&gt;Remove-SSHSession -SessionId $sshSession.SessionId | Out-Null&lt;BR /&gt;Write-Host -ForegroundColor DarkGray "`n------------------------------------------------------------------`n"&lt;/P&gt;&lt;P&gt;$resultsArray += New-Object -TypeName psobject -Property $resultsProperty&lt;BR /&gt;$i++&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;$resultsArray | Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count } -Descending | Out-GridView&lt;/P&gt;&lt;P&gt;$resultsArray | Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count } -Descending | Export-Excel -Path "$downloadsDir\Config_Check.xlsx"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is, the Tx_ring_size and Rx_ring_size fields are not being populated in the results array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Aug 2021 13:10:59 GMT</pubDate>
    <dc:creator>piercj2</dc:creator>
    <dc:date>2021-08-20T13:10:59Z</dc:date>
    <item>
      <title>Posh-ssh output to array</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Posh-ssh-output-to-array/m-p/2863035#M102855</link>
      <description>&lt;P&gt;Hi, i'm using Posh SSH to check some config settings&amp;nbsp;&lt;/P&gt;&lt;P&gt;The specific command i'm interested in is&amp;nbsp;&lt;STRONG&gt;Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Output from&amp;nbsp;&lt;STRONG&gt;Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"&lt;/STRONG&gt; is&lt;/P&gt;&lt;P&gt;Host : myServerNameHere.mycomp.com&lt;BR /&gt;Output : {Tx_ring_size : 4096}&lt;BR /&gt;ExitStatus : 0&lt;/P&gt;&lt;P&gt;Creating a Posh-SSH Session and running the command works as expected.&lt;/P&gt;&lt;P&gt;$sshUsername = 'admin'&lt;BR /&gt;$password = 'notThePassword!'&lt;BR /&gt;$sshPassword = $password | ConvertTo-SecureString -AsPlainText -Force&lt;BR /&gt;$sshPassword.MakeReadOnly()&lt;BR /&gt;$sshCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $sshUsername,$sshPassword&lt;BR /&gt;$sshCredential = Get-Credential -Credential $sshCred&lt;/P&gt;&lt;P&gt;$sshSession = New-SSHSession -ComputerName 'myServerNameHere.mycomp.com' -Credential $sshCredential -AcceptKey:$true&lt;BR /&gt;if ($sshSession.Connected -like "True") {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$Tx_ring_size = Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"&lt;BR /&gt;Write-Host "Tx_ring_size is: " -NoNewline&lt;BR /&gt;(($Tx_ring_size.Output -split ':')[1]).Trim("{","}")&lt;BR /&gt;&lt;BR /&gt;$Rx_ring_size = Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Rx_ring_size"&lt;BR /&gt;Write-Host "Rx_ring_size is: " -NoNewline&lt;BR /&gt;(($Rx_ring_size.Output) -split ':')[1]&lt;/P&gt;&lt;P&gt;Write-Host "Disconnecting ssh session to myServerNameHere.mycomp.com "&lt;BR /&gt;Remove-SSHSession -SessionId $sshSession.SessionId | Out-Null&lt;BR /&gt;Write-Host -ForegroundColor DarkGray "`n------------------------------------------------------------------`n"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;Output to the console is as expected&lt;/P&gt;&lt;P&gt;Tx_ring_size is: 4096&lt;BR /&gt;Rx_ring_size is: 4096&lt;BR /&gt;Disconnecting ssh session to myServerNameHere.mycomp.com&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to create a report for a large number of Servers by entering the details into an array and outputting the contents of the array&lt;/P&gt;&lt;P&gt;$ServerNameArray = @()&lt;/P&gt;&lt;P&gt;$resultsArray = @()&lt;/P&gt;&lt;P&gt;$downloadsDir = "$HOME\Downloads"&lt;/P&gt;&lt;P&gt;foreach ($item in $ServerNameArray){&lt;/P&gt;&lt;P&gt;$resultsProperty = [ordered] @{&lt;BR /&gt;'Server_FQDN'=$item.FQDN&lt;BR /&gt;'Server_IP' = $item.IP&lt;/P&gt;&lt;P&gt;$sshUsername = 'admin'&lt;BR /&gt;$password = 'notThePassword!'&lt;BR /&gt;$sshPassword = $password | ConvertTo-SecureString -AsPlainText -Force&lt;BR /&gt;$sshPassword.MakeReadOnly()&lt;BR /&gt;$sshCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $sshUsername,$sshPassword&lt;BR /&gt;$sshCredential = Get-Credential -Credential $sshCred&lt;/P&gt;&lt;P&gt;$sshSession = New-SSHSession -ComputerName 'myServerNameHere.mycomp.com' -Credential $sshCredential -AcceptKey:$true&lt;BR /&gt;if ($sshSession.Connected -like "True") {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;$Tx_ring_size = Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"&lt;BR /&gt;Write-Host "Tx_ring_size is: " -NoNewline&lt;BR /&gt;(($Tx_ring_size.Output -split ':')[1]).Trim("{","}")&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$resultsProperty.Add("Tx_ring_size",(($Tx_ring_size.Output -split ':')[1]).Trim("{","}"))&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;$Rx_ring_size = Invoke-SSHCommand -sessionID $sshSession.SessionId -Command "get dataplane | find Rx_ring_size"&lt;BR /&gt;Write-Host "Rx_ring_size is: " -NoNewline&lt;BR /&gt;(($Rx_ring_size.Output) -split ':')[1]&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;$resultsProperty.Add("Rx_ring_size",(($Rx_ring_size.Output -split ':')[1]).Trim("{","}"))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Write-Host "Disconnecting ssh session to myServerNameHere.mycomp.com "&lt;BR /&gt;Remove-SSHSession -SessionId $sshSession.SessionId | Out-Null&lt;BR /&gt;Write-Host -ForegroundColor DarkGray "`n------------------------------------------------------------------`n"&lt;/P&gt;&lt;P&gt;$resultsArray += New-Object -TypeName psobject -Property $resultsProperty&lt;BR /&gt;$i++&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;$resultsArray | Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count } -Descending | Out-GridView&lt;/P&gt;&lt;P&gt;$resultsArray | Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count } -Descending | Export-Excel -Path "$downloadsDir\Config_Check.xlsx"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is, the Tx_ring_size and Rx_ring_size fields are not being populated in the results array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 13:10:59 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Posh-ssh-output-to-array/m-p/2863035#M102855</guid>
      <dc:creator>piercj2</dc:creator>
      <dc:date>2021-08-20T13:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Posh-ssh output to array</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Posh-ssh-output-to-array/m-p/2863038#M102856</link>
      <description>&lt;P&gt;Not sure if that is the reason here, but some curly braces are missing and others are not alligned.&lt;BR /&gt;I think it should be something like this&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$ServerNameArray = @()

$resultsArray = @()

$downloadsDir = "$HOME\Downloads"

foreach ($item in $ServerNameArray) {

  $resultsProperty = [ordered] @{
    'Server_FQDN' = $item.FQDN
    'Server_IP' = $item.IP
  }
  $sshUsername = 'admin'
  $password = 'notThePassword!'
  $sshPassword = $password | ConvertTo-SecureString -AsPlainText -Force
  $sshPassword.MakeReadOnly()
  $sshCred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $sshUsername, $sshPassword
  $sshCredential = Get-Credential -Credential $sshCred

  $sshSession = New-SSHSession -ComputerName 'myServerNameHere.mycomp.com' -Credential $sshCredential -AcceptKey:$true
  if ($sshSession.Connected -like "True") {


    $Tx_ring_size = Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "get dataplane | find Tx_ring_size"
    Write-Host "Tx_ring_size is: " -NoNewline
    (($Tx_ring_size.Output -split ':')[1]).Trim("{", "}")

    $resultsProperty.Add("Tx_ring_size", (($Tx_ring_size.Output -split ':')[1]).Trim("{", "}"))

    $Rx_ring_size = Invoke-SSHCommand -SessionId $sshSession.SessionId -Command "get dataplane | find Rx_ring_size"
    Write-Host "Rx_ring_size is: " -NoNewline
    (($Rx_ring_size.Output) -split ':')[1]

    $resultsProperty.Add("Rx_ring_size", (($Rx_ring_size.Output -split ':')[1]).Trim("{", "}"))

    Write-Host "Disconnecting ssh session to myServerNameHere.mycomp.com "
    Remove-SSHSession -SessionId $sshSession.SessionId | Out-Null
    Write-Host -ForegroundColor DarkGray "`n------------------------------------------------------------------`n"

    $resultsArray += New-Object -TypeName psobject -Property $resultsProperty
    $i++
  }
}

$resultsArray | Sort-Object -Property { ($_ | Get-Member -MemberType NoteProperty).Count } -Descending | Out-GridView

$resultsArray | Sort-Object -Property { ($_ | Get-Member -MemberType NoteProperty).Count } -Descending | Export-Excel -Path "$downloadsDir\Config_Check.xlsx"
&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 20 Aug 2021 13:28:10 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Posh-ssh-output-to-array/m-p/2863038#M102856</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2021-08-20T13:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Posh-ssh output to array</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Posh-ssh-output-to-array/m-p/2863045#M102858</link>
      <description>&lt;P&gt;That was it, thanks Luc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 13:48:44 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Posh-ssh-output-to-array/m-p/2863045#M102858</guid>
      <dc:creator>piercj2</dc:creator>
      <dc:date>2021-08-20T13:48:44Z</dc:date>
    </item>
  </channel>
</rss>

