Automation

 View Only
  • 1.  Export PortGroup uplink details

    Posted Aug 29, 2022 04:52 AM

    We all know that the Standard switch is normally used for the management network of the hosts, and this switch has configurable uplinks (for example Active & Standby uplinks).

    Today I was analysing a host failure on the weekend where one of the uplinks went down but a few hosts went into network isolation- isolating themselves from the vCenter. I checked the Standard switch uplinks and they are both Active.

    I then checked the Management PortGroup, as it too can have configured uplinks, and I found one of the uplinks configured as StandBy, and thus the reason why those hosts failed.

    I now want to run a PowerShell script to check all hosts in the cluster and I came up with this, with help from an existing script I found:

     

    My problem is with the returned values for "PortGroup Active NIC" & "PortGroup StandBy NIC" which appear like this:

     

    If I run the command from the commandline, I get this:

     

    My goal is to set the property "PortGroup Active NIC" to "vmnic0, vmnic3".

    From the commandline, this seems to work:

    I'm not sure how to do this in the original code tho.

     

     



  • 2.  RE: Export PortGroup uplink details

    Posted Aug 29, 2022 05:10 AM

    Try with



  • 3.  RE: Export PortGroup uplink details

    Posted Aug 29, 2022 10:03 AM

    For the Management port group of my test host, I purposely put vmnic0 as active and vmnic4 as unused and got the following results:

    Which does not seem right.

     



  • 4.  RE: Export PortGroup uplink details

    Posted Aug 29, 2022 10:09 AM

    I manually ran each line as such:

     

     

     

     

     

    Looks like there may be something wrong with $PG?



  • 5.  RE: Export PortGroup uplink details
    Best Answer

    Posted Aug 29, 2022 10:17 AM

    Can you try with



  • 6.  RE: Export PortGroup uplink details

    Posted Aug 30, 2022 11:27 PM

    That worked well, thanks. Can you explain how this line works?

     

     

    To me it looks like, if the port group $PG exists, then......do this.

    Amazing solution btw.

     

    One other question: I ran the modified code for all distributed switches and it's been running for 24 hours now- we only have about 3 distributed switches in our environment. I presume that this line is taking a while to run, is there any way to modify the code so that the line runs once and the properties ActiveNic, StandByNic & UnusedNic can be added to the collection?

     

     

    I also modified the script so that it should be able to report on only either Standard or Distributed switches, here's the modifications:

     

     

    Thanks.

     

     

     

     

     

     



  • 7.  RE: Export PortGroup uplink details

    Posted Aug 31, 2022 06:03 AM

    That is an alternative to the Where-Object cmdlet.
    It's faster, that's why I prefer to use it this way.
    It tests if there is a value in the elements of the ActiveNic and StandbyNic arrays.
    Without that test you would end up with a number of commas without values between them.