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
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?
Pingback: Detailed ESXi network information – Waverley Cloud Blog
Hi Alan,
Great script it already save time for a project.
Is it possible to add the virtual switch name using the nics?
regards
Thx, this is modified from yours for performance. Needs a little clean up, there’s a line or two that don’t really do much.
http://communities.vmware.com/people/Ranger69/blog/2012/04/05/cisco-discovery-protocol-cdp-information-via-powercli
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 🙂
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.
🙁
Very nice script. Is it possible to add Management address for DeviceID and vSwitch information for PNICs in report? Regards
Bugger… wrong post… above comment should have been for the http://www.virtu-al.net/vcheck-pluginsheaders/vcheck/ post
Sorry
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
works pretty well, excellect job Alan 🙂
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
Yeah I know the issue, some of the properties for that object are not the same as Standard vSwitches so it doesnt work properly.
Concerning dvSwitches…. it does show some properties but not d()vSwitch name and PrtInUse
Perfect script… is there a way to add the Network Label as well?
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..
I think that would be very helpfull.
How can we add the port group names to this? IE, the console port names, etc.
Pingback: CDP Info on ESX from the Command-Line
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?
Thanks a lot for your Help 😉
@Wolficool
No Problem,
A good place to start is this post I created a little while ago…
http://www.virtu-al.net/2009/11/10/powercli-where-do-i-start/
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.
@Wolficool
Line 4 which starts $vmhosts = Get-VMHost…….
Change it to $vmhosts = Get-Cluster “MyCluster” | Get-VMHost…..
That should do the trick 😉
Hi,
Great Script!!!
But how can i Change this script to report this to a Completly Cluster??
Added the VSwitch info as requested…. http://teckinfo.blogspot.com/2009/02/more-network-info.html
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!
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.
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
Please disregard previous comment, I was trying to enter the hostname at the command line
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?