Detailed VMware Host Network Information

Following my previous script ‘Extracting Cisco Discovery Protocol Info‘ I decided to tidy up the script, give a more controlled output and add a few items to the output.

The following script will add some nice host network information into an object which is exported to a csv file for passing to the network guys or can be used to find your server in that mess of cables that are always meaning to be tidied in the data center.

You will get:

  • Host,
  • Physical Nic Name
  • Speed
  • MAC
  • Switch Device ID
  • Port ID
  • Observed Network ranges
  • VLAN’s

30 thoughts on “Detailed VMware Host Network Information

  1. Jegadeesh

    Awesome script!!! Great Job!! can you please help me adding Virtual switch, Portgroup and Portgroup VLAN information for the corresponding physical nics to this script?

  2. Pingback: Detailed ESXi network information – Waverley Cloud Blog

  3. gram

    Hi Alan,
    Great script it already save time for a project.
    Is it possible to add the virtual switch name using the nics?
    regards

  4. Alex

    Hi! Thanks for this script, it’s great! We are using LLDP instead of CDP and that info is not picked up by this script, however I was able to modify it to retreive the same information. I’d like to share this with you and others who might find it usefull.

    replace the lines:
    $NetworkInfo.DeviceID = $Hint.connectedSwitchPort.DevId
    $NetworkInfo.PortID = $Hint.connectedSwitchPort.PortId
    with:
    foreach ($parameter in $Hint.lldpinfo.parameter) {
    if ($parameter.key -eq “System Name”) { $NetworkInfo.DeviceID = $parameter.value}
    if ($parameter.key -eq “Port Description”) { $NetworkInfo.PortID = $parameter.value}
    }

    The “PortID” value, from a procurve switch, is “GigabitEthernetx/y/z Interface”, where “z” is the port number, “x” the switch number and, I guess, “y” the module number. For two switches connected by IRF, the DeviceID is the same and “x” is the switch node number, starting at 1.

    It’s more of a hack than a solution, but it was a quick solution 🙂

  5. David

    Did not worked for me. Getting the error:

    Cannot index into a null array.
    At C:\PSScripts\WK HA Assessment\detailednetwork.ps1:25 char:63
    + If ($Hint.Device -eq $vmhost.Config.Network.Pnic[ <<<< $record].Device){
    + CategoryInfo : InvalidOperation: (475:Int32) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

    Cannot index into a null array.

    🙁

  6. Guillermo

    Very nice script. Is it possible to add Management address for DeviceID and vSwitch information for PNICs in report? Regards

  7. Christian

    Hi Alan,

    Downloaded the script today, and played around a bit with the vCheckUtils.
    When tryint to add a plugin, it fails to download the file. Looking in the online plugins.xml, reveals that for each listed plugin, a / is missing after http://virtu-al.net/vcheck/plugins/vSphere.

    Thought you might want to know 🙂

    /Christian

  8. H

    Very nice script, but I ran into the following problem:

    Running this script on a Host in Maintenance mode loops forever
    Cannot index into a null array.
    At C:\oops.ps1:20 char:63
    + If ($Hint.Device -eq $vmhost.Config.Network.Pnic[ <<<< $record].Device){
    + CategoryInfo : InvalidOperation: (198:Int32) [], RuntimeException

  9. Alan Post author

    Yeah I know the issue, some of the properties for that object are not the same as Standard vSwitches so it doesnt work properly.

  10. daunce

    Great script. Is it much work to have the vlanid field sorted ascending? at the moment it prints out ” 1 2 3 4″, then next line “4 2 3 1” etc..

  11. Jared Davis

    How can we add the port group names to this? IE, the console port names, etc.

  12. Pingback: CDP Info on ESX from the Command-Line

  13. amin

    i m getting the same error and i did put the host name because i only want to get info from one host. i m connected to the Vcenter
    if i run the commands it do get the in upt to get-view but after that this error. any advise. i m new to this scripting thing.

    $vmhosts = Get-VMHost | Sort Name | Where-Object {$_.State -eq “abcdpr1.abcd.com”} | Get-View
    Getting can’t index null array on the line

    If ($Hint.Device -eq $vmhost.Config.Network.Pnic[$ <<<< record].

    It seems to loop there. Any suggestions? Also what program did you use to compile this, how do you code this?

  14. Wolficool

    Thanks a lot for your help.

    Where do you have all this informations?? I have not seen any book or what else to read more about scripting.

  15. Virtu-Al

    @Wolficool
    Line 4 which starts $vmhosts = Get-VMHost…….

    Change it to $vmhosts = Get-Cluster “MyCluster” | Get-VMHost…..

    That should do the trick 😉

  16. Wolficool

    Hi,

    Great Script!!!

    But how can i Change this script to report this to a Completly Cluster??

  17. Anonymous

    Worked flawless for me… Thank you very much…
    Can you please add the Virtual Switch Name “vSwtich1” to the table as well? Your Scripts rock, Great job!

  18. Virtu-Al

    Sorry about that, the blog took some of the formatting out, I have changed it so you should be able to get the working version now.

  19. Anonymous

    I get the following error:

    Unexpected token 'select-Object' in expression or statement.
    At C:\networkinfo.ps1:13 char:42
    + $NetworkInfo = "" select-Object <<<< Host, PNic, Speed, MAC, DeviceID, PortID, Observed, VLAN

  20. Anonymous

    Please disregard previous comment, I was trying to enter the hostname at the command line

  21. Anonymous

    Getting can't index null array on the line

    If ($Hint.Device -eq $vmhost.Config.Network.Pnic[$ <<<< record].

    It seems to loop there. Any suggestions? Also what program did you use to compile this, how do you code this?

Leave a Reply to Fred

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.