0

I'd like to create a powershell script to show which network interface is down from the get-vmswitchteam and get-netadapter output comparison.

What I'd like to achieve:

  1. Check the name of the Get-VMSwitchTeam members
  2. Check those names are up or down in the output of the get-netadapter
  3. If not up, alert

However I can't refer to the object inside the array so I can't compare the values between the get-netadapter and get-vmswitchteam. I've used to use the Get-NetLbfoTeamMember but this doesn't have any output in my new system.

This is the adapters in the teaming:

$adapters=(Get-VMSwitchTeam -Name "Teaming"|Select-Object NetAdapterInterfaceDescription)
$adapters

NetAdapterInterfaceDescription
------------------------------
{HPE FlexFabric 10Gb 4-port 536FLR-T Adapter #4, HPE FlexFabric 10Gb 4-port 536FLR-T Adapter #2}

One interface is down (disabled):

get-netadapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
Embedded FlexibleLOM ...2 HPE FlexFabric 10Gb 4-port 536FLR-...#2      10 Disabled     08-xxx-62        10 Gbps
Embedded FlexibleLOM ...1 HPE FlexFabric 10Gb 4-port 536FLR-...#4      11 Up           08-xxx-60        10 Gbps

If I use

$adapters -split ","

I got this which is not the name of interface:

@{NetAdapterInterfaceDescription=System.String[]}

How can I get the list of the interfaces in get-vmswitchteam that I can use with some if statement to compare with get-netadapter?

If I try to refer to the object in the array like $adapters[1] ... it shows the character at that position which I guess okay, but that is not I'd like to achieve.

Thank you for your help

Badb0y
  • 331
  • 2
  • 21
  • 2
    How about `$adapters.NetAdapterInterfaceDescription -split "," ` ? – Roshan Nuvvula Nov 01 '22 at 05:45
  • Perfect, thank you very much, this is what I want! Can you explain very briefly why this is the solution? I don't get why need double time to filter :/ – Badb0y Nov 01 '22 at 07:25
  • Use the [Array subexpression operator `@()`](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operators#array-subexpression-operator--) to also force an array that contains only one element: `@($adapters)[1]` – iRon Nov 01 '22 at 08:32
  • [`Select-Object`](https://docs.microsoft.com/powershell/module/microsoft.powershell.utility/select-object) (`select`) by default returns _a `[pscustomobject]` instance_ that has the _requested properties_ - even when you're only asking for a _single_ property. To get only that property's _value_, use `-ExpandProperty $propertyName` instead - see the [this post](https://stackoverflow.com/q/48807857/45375) for details and alternatives, notably the ability to simply use `(...).$propertyName` – mklement0 Nov 01 '22 at 09:01
  • 1
    In other words: use `$adapters=(Get-VMSwitchTeam -Name "Teaming").NetAdapterInterfaceDescription` – mklement0 Nov 01 '22 at 09:02
  • Best way I found is to cast object to correct type by using ForEach : $myArray.ForEach([new type]). – jdweng Nov 01 '22 at 09:07
  • @iRon Arrays starts at [0]. Isn't that what should be used? – Dennis Nov 01 '22 at 17:46
  • @Dennis that doesn't work, it gives back the same – Badb0y Nov 02 '22 at 01:22
  • 1
    @mklement0 perfect this too – Badb0y Nov 02 '22 at 01:22

0 Answers0