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

29 thoughts on “Detailed VMware Host Network Information”

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

  2. 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 🙂

  3. 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.

    🙁

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

  5. 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

  6. 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

  7. 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..

  8. 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?

  9. 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.

  10. 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!

  11. 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.

  12. 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

  13. 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