hi,
I need two powershell scripts for collecting two types of ESX host network information,
1. vNIC information --> the information about the vmnic(physical nic of ESX hosts) connected to vSwitches.
vNIC | Model | vSwitch | Portgroups | Speed | Status | PCI Location | Active/stand-by/unassigned
Expected output(Example):
vmnic0 | intel corporation 82XXXX gigabit ethernet controller | vSwitch0 | service console, vMotion | 1000mbps Full | up | 01:01.00 | Active
2. Portgroup information
Portgroup | vNIC(s) with active/standby | PCI location of vNIC(s) with active/standby | Physical switch with port number
Expected Output (Example):
Service console | vmnic0(a) : vmnic1(s) | 01:00.00(a) : 02:00.00(s) | abcd-123[GigabitEthernet10/10] : xyzf-7890[Gigabitethernet11/11]
Please note if CDP not enabled, then in values of physical switch field can contain "CDP not enabled"
Thanks in advance!
ok so at the top of the report I added a connect-viserver servervc01
after I run the script I get the following errors in the debug window over and over again
Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At line:18 char:35
+ $row.Portgroups = ::Join <<<< (",", ($pg | %{$_.Name}))
+ CategoryInfo : NotSpecified: ( [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Exception calling "Join" with "2" argument(s): "Value cannot be null.
Parameter name: value"
At line:18 char:35
+ $row.Portgroups = ::Join <<<< (",", ($pg | %{$_.Name}))
+ CategoryInfo : NotSpecified: ( [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Do you get the same error when you run it from a PowerCLI prompt ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I run the script from the PowerCLI interface just ./script.ps1
Attached is the lastest version of the script, create a directory on your C drive for the following poath C:\Scripts\GetNetworkInfo\ place the script in there, open PowerCLI and change directories to C:\Scripts\GetNetworkInfo\ and then run the script ./pnic-report.ps1
make sure you put in your FQDN for the vCenter and your username and password. If your using a domain account list it in the username section as domain\username
this script takes a bit to run depending on how many hosts you have.
Also it appears it will throw an error on the portgroup line for any host without CDP enabled
Exception calling "Join" with "2" argument(s): "Value cannot be null. Parameter name: value" At C:\Scripts\GetNetworkInfo\pnic-report.ps1:25 char:36 + $row.Portgroups = [string]::Join <<<< (",", ($pg | %{$_.Name})) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
Cheers,
Bradley Sessions
If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Luc,
Everything is working correctly, it just throws an error on the portgroups when the link is down or CDP isn't configured. Is there anyway to add the observed Vlan to the observed IPranges line?
It seems like the Vlan should be in the () in the output below but it's not, is there something else I need to add to the line?
$row.IPrange = [string]::Join("/",@($cdpInfo[0].Subnet | %{$_.IpSubnet + "(" + $type + ")"}))
Output
IPrange 10.227.128.10-10.227.128.10()/161.134.216.64-161.134.216.127()/169.254.0.1-169.254.127.254()/169.254.0.1-169.254.255.254()/161.134.221.1-161.134.221.31()/160.0.0.1-175.255.255.254()/161.134.217.134-161.134.217.134()/10.226.128.1-10.226.128.254()/172.18.70.4-172.18.70.7()/161.134.221.208-161.134.221.211()/160.0.0.1-175.255.255.254()/172.18.113.4-172.18.113.5()/169.254.35.255-169.254.35.254()
Cheers,
Bradley Sessions
If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Fixed the problem with the portgroups and added the VLAN Id to the output.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
anyway to grab the vKernel and Service Console IPs in this?
Cheers,
Bradley Sessions
If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
Hi Luc,
Can you please re-write this script to include portgroup from dvSwitch also so that dvSwitch portgroups are reported along with standard vSwitch portgroup per host? Much needed
Bump.. did anyone ever get anywhere with the request for dvswitch info? It would be super-useful....
TIA
I know this is an old post, but i really wanted to say THANK YOU LucD! These scripts just saved me a lot of time
Bump on the script.
LucD you are a life saver
HI lucd please let me know how can i retrive the result of this script in csv file.
Thanks
Pravinu.
The last script I attached saves the result to a CSV file.
But watch out, there is an error in that it always saves to the same CSV file.
Change this line
$report | export-csv C:\Scripts\GetNetworkInfo\networkinfo.csv -NoTypeInformation
into something like this
$report | export-csv C:\Scripts\$singleViserver-GetNetworkInfo\networkinfo.csv -NoTypeInformation
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference