Forum Discussion

JulianMilano's avatar
JulianMilano
Copper Contributor
Aug 05, 2023
Solved

It's time to make an exception

My script logs into the CIMC of my Cisco servers to gather hardware information. There's one particular server which it seems the CIMC is not responding and instead of getting a "unable to connect" e...
  • LainRobertson's avatar
    Aug 06, 2023

    JulianMilano 

     

    I can't see anything wrong with your code.

     

    The only thing that makes sense to me is that the thrown exception is not actually of the type [System.NullReferenceException], but since I can't replicate your scenario, I'm simply making an educated guess.

     

    From a diagnostic perspective, I'd verify the exception's type inheritance manually using:

     

    try
    {
        Connect-IMC -Name $RackServerIMCIP -Credential $IMCServerCredential -NotDefault -ErrorAction:Stop
    }
    catch
    {
        $_.Exception.pstypenames;
    }

     

    Where the top-most type name is the most specific to the exception, becoming less so as you read downwards.

     

    Here's a simple example to illustrate the output:

     

     

    Cheers,

    Lain

Resources