Automation

 View Only
  • 1.  get switch

    Posted Jun 04, 2018 11:54 AM

    Hello, I use this script to get some network adapter information, I would like to get also switch too,

    Get-VMHostNetworkAdapter |

    Where-Object {$_.GetType().Name -eq "PhysicalNicImpl"} |

    Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,

      @{Name="AutoNegotiate";Expression={

        if ($_.ExtensionData.Spec.LinkSpeed)

          {$false} else {$true}

      }},

      @{Name="LinkState";Expression={

        if ($_.ExtensionData.LinkSpeed)

         {"Up"} else {"Down"}

      }} | Export-Csv -Path C:\Users\gemela\info.csv -NoTypeInformation -UseCulture

    Thanks



  • 2.  RE: get switch

    Posted Jun 04, 2018 05:58 PM

    Try something like this

    Get-VMHostNetworkAdapter -Physical |

    Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,

      @{Name="AutoNegotiate";Expression={

       if ($_.ExtensionData.Spec.LinkSpeed)

      {$false} else {$true}

      }},

      @{Name="LinkState";Expression={

       if ($_.ExtensionData.LinkSpeed)

      {"Up"} else {"Down"}

      }},

      @{N='vSwitch';E={

       $vnic = $_.Name

       Get-VirtualSwitch -VMHost $_.VMHost | where{$_.Nic -contains $vnic} | Select -ExpandProperty Name

      }}  | Export-Csv -Path C:\Users\gemela\info.csv -NoTypeInformation -UseCulture



  • 3.  RE: get switch

    Posted Jun 05, 2018 11:09 AM

    vSwitch record are empty in the csv



  • 4.  RE: get switch

    Posted Jun 05, 2018 11:21 AM

    Works for me, the vSwitch property is empty when the vmnic is not used in any vSwitch.
    Are you using VSS or VDS, or a mix of both types?



  • 5.  RE: get switch
    Best Answer

    Posted Jun 05, 2018 11:55 AM

    Ok, with VDS the vSwitch field is indeed blank.

    Try this variation.

    Get-VMHostNetworkAdapter -Physical |

    Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,

      @{Name="AutoNegotiate";Expression={

       if ($_.ExtensionData.Spec.LinkSpeed)

      {$false} else {$true}

      }},

      @{Name="LinkState";Expression={

       if ($_.ExtensionData.LinkSpeed)

      {"Up"} else {"Down"}

      }},

      @{N='vSwitch';E={

       $vmnic = $_.Name

       $esxcli = Get-EsxCli -VMHost $_.VMHost

       $sw = @($esxcli.network.vswitch.standard.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name)

       $sw += $esxcli.network.vswitch.dvs.vmware.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name

       $sw -join '|'}}



  • 6.  RE: get switch

    Posted Jun 06, 2018 08:32 AM

    This is perfect, thanks LucD.



  • 7.  RE: get switch

    Posted Jun 06, 2018 10:11 AM

    Hi LucD,

    One more question, Is possible to group the result? or get name of hardware? (one more column),

    It will be useful if I can recognize which Nic is part of Broadcom 10/20 Gigabit Ethernet and which Nic are part of Intel...

    Thanks a lot.



  • 8.  RE: get switch

    Posted Jun 06, 2018 11:45 AM

    Try like this

    Get-VMHostNetworkAdapter -Physical |

    Select-Object -Property VMHost,Name,BitRatePerSec,FullDuplex,Mac,DhcpEnabled,

      @{Name="AutoNegotiate";Expression={

       if ($_.ExtensionData.Spec.LinkSpeed)

      {$false} else {$true}

      }},

      @{Name="LinkState";Expression={

       if ($_.ExtensionData.LinkSpeed)

      {"Up"} else {"Down"}

      }},

      @{N='vSwitch';E={

       $script:vmnic = $_.Name

       $script:esxcli = Get-EsxCli -VMHost $_.VMHost

       $sw = @($esxcli.network.vswitch.standard.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name)

       $sw += $esxcli.network.vswitch.dvs.vmware.list() | where{$_.Uplinks -contains $vmNic} | select -ExpandProperty Name

       $sw -join '|'}},

      @{N='HW';E={

       $script:esxcli.network.nic.list() | where{$_.Name -eq $script:vmnic} | select -ExpandProperty Description}}



  • 9.  RE: get switch

    Posted Jun 06, 2018 01:57 PM

    Amazing, thanks LucD :-)