Reply to Message

View discussion in a popup

Replying to:
LucD
Leadership
Leadership

Not sure if that is the reason here, but some curly braces are missing and others are not alligned.
I think it should be something like this

$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"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post