To add some error handling I tried to use the try-catch syntax when calling the Invoke-CiscoCommand but this resulted in the first run succeeding but all subsequent runs failed with the error message below. I am looping through a set of Cisco switch IPs so I can create a file using ConvertTo-CSV and have a file for each switch. After the loop finished the Get-SSHSession showed a new session open for each subsequent call to invoke-ciscocommand.
`Get-CiscoFCNS -IPAddress 10.xxx.xx.xxx -Credentials System.Management.Automation.PSCredential
Invoke-CiscoCommand -IPAddress 10.xxx.xx.xxx -command 'show fcns database local detail | json native' -Credential System.Management.Automation.PSCredential
Get-CiscoFCNS : Cannot convert value "Stream found for {0}" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Support\Scripts\GatherCiscoSanSwitchConfigs.ps1:126 char:15
- ... $objFCNS = Get-CiscoFCNS -IPAddress $TheSwitch.IPAddress -Credential ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
- FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-CiscoFCNS`
To add some error handling I tried to use the try-catch syntax when calling the Invoke-CiscoCommand but this resulted in the first run succeeding but all subsequent runs failed with the error message below. I am looping through a set of Cisco switch IPs so I can create a file using ConvertTo-CSV and have a file for each switch. After the loop finished the Get-SSHSession showed a new session open for each subsequent call to invoke-ciscocommand.
`Get-CiscoFCNS -IPAddress 10.xxx.xx.xxx -Credentials System.Management.Automation.PSCredential
Invoke-CiscoCommand -IPAddress 10.xxx.xx.xxx -command 'show fcns database local detail | json native' -Credential System.Management.Automation.PSCredential
Get-CiscoFCNS : Cannot convert value "Stream found for {0}" to type "System.Int32". Error: "Input string was not in a correct format."
At C:\Support\Scripts\GatherCiscoSanSwitchConfigs.ps1:126 char:15