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!
The last script was for Suresh, the one before is for you.
Notice to who I replied.
It becomes difficult when we have 2 threads in 1
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
gotcha!! yeah tough thing when one like me threadjacks (sorry suresh) but i figured he had such a good idea to begin with, I just wanted a little tweak here or there.
I see what you mean about the vlan clutter, Im not sure how Id like it represented . I know I want to have a list so that I can verify the ones that show up and those that dont, but im open to suggestions on how to clean up the display. !Untitled picture.png|thumbnail=true!
Try this version.
At least the CSV is a bit more readable.
Not happy yet with the IP subnets though.
function Get-pNICInfo{ param($name, $type) $cdpInfo = $netSys.QueryNetworkHint($name) $row = "" | Select "ESXname","Portgroup","VLANid","IP range + VLAN","pNIC","PCI location","Physical switch" $row."ESXname" = $esxImpl.Name $row."Portgroup" = $pg.Spec.Name $row."VLANid" = $pg.Spec.VlanId $row."IP range + VLAN" = [string]::Join("/",($cdpInfo[0].Subnet | %{$_.IpSubnet + ' (VLAN ' + $_.VlanId + ')(' + $type + ')'})) $row."pNIC" = $name + "(" + $type + ")" $row."PCI location"=$esx.Config.Network.Pnic | where {$_.Device -eq $name} | %{$_.Pci + "(" + $type + ")"} $row."Physical switch"=&{if($cdpInfo[0].connectedSwitchPort){$cdpInfo[0].connectedSwitchPort.devId + "(" + $type + ")"}else{"CDP not configured(" + $type + ")"}} $row } $report = @() Get-VMHost | %{ $esxImpl = $_ $esx = $esxImpl | Get-View $netSys = Get-View $esx.ConfigManager.NetworkSystem foreach($pg in $esx.Config.Network.Portgroup){ foreach($a in $pg.ComputedPolicy.NicTeaming.NicOrder.ActiveNic){ if($a){ $report += (Get-pNICInfo $a "a") } } foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){ if($s){ $report += (Get-pNICInfo $s "s") } } } } $report | Export-Csv "C:\Nic-Info.csv" -NoTypeInformation -UseCulture
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
OK, so I tried this one, and good thing I was running the command line out of VESI, as the errors on the CDP info lit up my screen. the resulting csv file is now completely blank in the observed IP column.
Strange, ran this from the PowerCLI prompt and no errors what so ever.
Could you perhaps show one or two of the errors ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
so Ive got what might be a silly question\suggestion - is there a way to stick the IP range and VLAN into seperate columns? If you coudl do that, then maybe we can mask the IP clumn if we want. in our environment almost everything is trunked, so its the VLAN tags that are most important, but being able to seperate and switch between the two might help clean up the display... what do you think?
here you go
There we go again
The forum SW doesn't like square brackets.
I'll attach the script.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And this one has "IP range" and "IP range VLAN" split out.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
MUCH better!! in fact I just ran this across a big cluster and already see some missing VLANS this has been the only way to check if all the networking is right aside from when you hook a mahcine up and nothing works.
Thank you thank you thank you
Luc,
One more things, since CDP displays the switch it is connected to , is it possible to alos pull the port number for the nic? I think this script is turnign into a near perfect netowkr auditing script .
Luc,
Here you go.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
Thanks for this awesome script. Now the script is perfect and very close to the expected ouput which i asked for when i opened this thread.
Just need port number to be added,
Presently the ouput of physical switch value is like this,
Physical switch : {abcd-1234.xxxx.com(a), zyzf-1234.xxxx.com(s)}
Expected output(example)
Physical switch : {abcd-1234.xxxx.com(a):GigabitEthernet1/1(a), zyzf-1234.xxxx.com(s):GigabitEthernet2/2(s)}
Given correct and helpful aswers
Thanks. The following will include the portId.
foreach($esxImpl in (Get-VMHost)){ $esx = $esxImpl | Get-View $netSys = Get-View $esx.ConfigManager.NetworkSystem foreach($pg in $esx.Config.Network.Portgroup){ $pNICStr = @() $pciStr = @() $cdpStr = @() foreach($a in $pg.ComputedPolicy.NicTeaming.NicOrder.ActiveNic){ if($a){ $pNICStr += ($a + "(a)") $pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $a} | %{$_.Pci + "(a)"}) $cdpInfo = $netSys.QueryNetworkHint($a) $cdpStr += &{if($cdpInfo[0].connectedSwitchPort){ $cdpInfo[0].connectedSwitchPort.devId + "(a):" + $cdpInfo[0].connectedSwitchPort.PortId + "(a)" } else{"CDP not configured(a)"}} } } foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){ if($s){ $pNICStr += ($s + "(s)") $pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $s} | %{$_.Pci + "(s)"}) $cdpInfo = $netSys.QueryNetworkHint($s) $cdpStr += &{if($cdpInfo[0].connectedSwitchPort){ $cdpInfo[0].connectedSwitchPort.devId + "(s):" + $cdpInfo[0].connectedSwitchPort.PortId + "(s)" } else{"CDP not configured(s)"}} } } $pg | Select @{N="ESXname";E={$esxImpl.Name}}, @{N="Portgroup";E={$pg.Spec.Name}}, @{N="VLANid";E={$pg.Spec.VlanId}}, @{N="pNIC";E={$pNICStr}}, @{N="PCI location";E={$pciStr}}, @{N="Physical switch";E={$cdpStr}} } }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect. That's it. I got what i want. Thanks a lot for your patience in hearing all my queries and providing this wonderful script.
Have two more script requirement one for storage and other for VM inventory, which i will post soon, need your script for those.
Luc,
I have posted a new ESX Storage powershell script requirement in this link http://communities.vmware.com/thread/263312 Please check whether you have a script for this.
I'll have a look.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
Sorry to ask you a addtion to this script again. Can you please add a vSwitch field to the output. At present from the output i can't know in which vSwitch the portgroup exist. So the expected output looks like this,
ESXname :
Portgroup :
vSwitch :
VLANid :
pNIC :
PCI location :
Physical switch :
Here you go
foreach($esxImpl in (Get-VMHost)){ $esx = $esxImpl | Get-View $netSys = Get-View $esx.ConfigManager.NetworkSystem foreach($pg in $esx.Config.Network.Portgroup){ $pNICStr = @() $pciStr = @() $cdpStr = @() foreach($a in $pg.ComputedPolicy.NicTeaming.NicOrder.ActiveNic){ if($a){ $pNICStr += ($a + "(a)") $pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $a} | %{$_.Pci + "(a)"}) $cdpInfo = $netSys.QueryNetworkHint($a) $cdpStr += &{if($cdpInfo[0].connectedSwitchPort){ $cdpInfo[0].connectedSwitchPort.devId + "(a):" + $cdpInfo[0].connectedSwitchPort.PortId + "(a)" } else{"CDP not configured(a)"}} } } foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){ if($s){ $pNICStr += ($s + "(s)") $pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $s} | %{$_.Pci + "(s)"}) $cdpInfo = $netSys.QueryNetworkHint($s) $cdpStr += &{if($cdpInfo[0].connectedSwitchPort){ $cdpInfo[0].connectedSwitchPort.devId + "(s):" + $cdpInfo[0].connectedSwitchPort.PortId + "(s)" } else{"CDP not configured(s)"}} } } $pg | Select @{N="ESXname";E={$esxImpl.Name}}, @{N="vSwitch";E={($esx.Config.Network.Vswitch | where {$_.Key -eq $pg.Vswitch}).Name}}, @{N="Portgroup";E={$pg.Spec.Name}}, @{N="VLANid";E={$pg.Spec.VlanId}}, @{N="pNIC";E={$pNICStr}}, @{N="PCI location";E={$pciStr}}, @{N="Physical switch";E={$cdpStr}} } }
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference