VMware Cloud Community
Sureshadmin
Contributor
Contributor
Jump to solution

Need powershell script to collect ESX host Network Info

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!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Noticed that the two sub-threads became a bit mixed up in the script.

This is the script with the devIds with the active/standby indication.

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)"}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)"}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

View solution in original post

0 Kudos
71 Replies
LucD
Leadership
Leadership
Jump to solution

Part 1, this should get you the pNIC information.

foreach($esxImpl in (Get-VMHost)){ 
	$esx = $esxImpl | Get-View
	foreach($pnic in $esx.Config.Network.Pnic){
		$vSw = $esxImpl | Get-VirtualSwitch | where {$_.Nic -contains $pNic.Device}
		$pg = $esxImpl | Get-VirtualPortGroup | where {$_.VirtualSwitchName -eq $vSw.Name}
		$order = ($esx.Config.Network.Vswitch | where {$_.Name -eq $vSw.Name}).Spec.Policy.NicTeaming.NicOrder
		$pnic | Select @{N="ESXname";E={$esxImpl.Name}},
			@{N="pNic";E={$pnic.Device}}, 
			@{N="Model";E={($esx.Hardware.PciDevice | where {$_.Id -eq $pnic.Pci}).DeviceName}},
			@{N="vSwitch";E={$vSw.Name}},
			@{N="Portgroups";E={$pg | %{$_.Name}}},
			@{N="Speed";E={$pnic.LinkSpeed.SpeedMb}},
			@{N="Status";E={if($pnic.LinkSpeed -ne $null){"up"}else{"down"}}},
			@{N="PCI Location";E={$pnic.Pci}},
			@{N="Active/stand-by/unassigned";E={if($order.ActiveNic -contains $pnic.Device){"active"}elseif($order.StandByNic -contains $pnic.Device){"standby"}else{"unused"}}}
	}
}

I have added the ESXName property, that way the script can run against all ESX servers.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

LucD
Leadership
Leadership
Jump to solution

Part 2 of your question.

Not too sure about the CDP part since I couldn't test it

foreach($esxImpl in (Get-VMHost)){ 
	$esx = $esxImpl | Get-View
	$netSys = Get-View $esx.ConfigManager.NetworkSystem
	$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.hardwarePlatform}else{"CDP not configured"}}
		}
	}
	foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){
		if($s){
			$pNICStr += ($s + "(s)")
			$pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $a} | %{$_.Pci + "(s)"})
		}
	}

	$pg | Select @{N="ESXname";E={$esxImpl.Name}},
		@{N="Portgroup";E={$pg.Spec.Name}}, 
		@{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

Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

I connected to one of my ESX 3.5 host and ran the both scripts, here are the results.

Part 1 script is working perfect.

Part 2 script is just giving out the ESX name and all other fields are blank. have pasted the output below,

ESXname : xxx.x.xxx.xxx Portgroup : pNIC : {} PCI location : {} Physical switch : {}

Any ideas?

Just crossed the IP address of my esx host, all other fields are as is, as per the output.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, a copy/paste error on my side.

This is the correct script

foreach($esxImpl in (Get-VMHost)){ 
	$esx = $esxImpl | Get-View
	$netSys = Get-View $esx.ConfigManager.NetworkSystem
	$pNICStr = @()
	$pciStr = @()
	$cdpStr = @()
	foreach($pg in $esx.Config.Network.Portgroup){
		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.hardwarePlatform}else{"CDP not configured"}}
			}
		}
		foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){
			if($s){
				$pNICStr += ($s + "(s)")
				$pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $a} | %{$_.Pci + "(s)"})
			}
		}

		$pg | Select @{N="ESXname";E={$esxImpl.Name}},
		@{N="Portgroup";E={$pg.Spec.Name}}, 
		@{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

0 Kudos
kwharrisit
Contributor
Contributor
Jump to solution

Im looking at a version of this information as well. Do you know if this might also report the VLANs observed on each pNIC? Im trying to verify that each trunk port is set up correctly.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik, the VLANid is related to the portgroups not the pNICs.

The VLANid for each portgroup can easily be included like this

foreach($esxImpl in (Get-VMHost)){ 
	$esx = $esxImpl | Get-View
	$netSys = Get-View $esx.ConfigManager.NetworkSystem
	$pNICStr = @()
	$pciStr = @()
	$cdpStr = @()
	foreach($pg in $esx.Config.Network.Portgroup){
		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.hardwarePlatform}else{"CDP not configured"}}
			}
		}
		foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){
			if($s){
				$pNICStr += ($s + "(s)")
				$pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $a} | %{$_.Pci + "(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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

I ran the script with one of my ESX 3.5 box. But got the output in the following format. In this ESX box there are 3 portgroups Service console, vMotion, virtualmachines.

1. The portgroups service console and vMotion uses the same vswitch and vmnic0 and vmnic1 are active and standby. But the PCI location is same for both the vmnic in the result and for vmotion portgroup the result shows repeated vmnics.

2. The virtualmachines portgroup is on another vswitch where vmnic2, vmnic3 are active, standby. But its reported wrong by the script as vmnic0, vmnic1 and its repeated.

3. Also i need the device name of the physicalswitch and not the hardware model like Cisco WS-xxxx

I checked with PowerCLI and VESI script editor both, but both gives the same output as below.

Can you help in this?

OUTPUT:

ESXname : xxx.x.xxx.xxx

Portgroup : Service Console

pNIC : {vmnic0(a), vmnic1(s)}

PCI location :

Physical switch : cisco WS-xxxx

ESXname : xxx.x.xxx.xxx

Portgroup : Network-VMotion

pNIC : {vmnic0(a), vmnic1(s), vmnic0(a), vmnic1(s)}

PCI location :

Physical switch : {cisco WS-xxxx, cisco WS-xxxx}

ESXname : xxx.x.xxx.xxx

Portgroup : virtualmachines

pNIC : {vmnic0(a), vmnic1(s), vmnic0(a), vmnic1(s)...}

PCI location :

Physical switch : {cisco WS-xxxx, cisco WS-xxxx, cisco WS-xxxx}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

1) & 2) That was my fault, the initialisation of variables should have been done inside the portgroup loop.

3) I suspect you the Device property then. Otherwise have a look at the PhysicalNicHintInfo object and let me know which property you want.

Try it with this code

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].Device){$cdpInfo[0].Device}else{"CDP not configured"}}
			}
		}
		foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){
			if($s){
				$pNICStr += ($s + "(s)")
				$pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $a} | %{$_.Pci + "(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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

Ran this script and got the output given below,

1. The PCI location for the active and standby nics are same.

2. For physical switch it shows vmnic name, had a look at the link you gave me to select the property, i want devID property which is given in this link

OUTPUT

ESXname : xxx.x.xxx.xxx

Portgroup : Service Console

VLANid : 0

pNIC : {vmnic0(a), vmnic1(s)}

PCI location :

Physical switch : vmnic0

ESXname : xxx.x.xxx.xxx

Portgroup : VMotion

VLANid : 0

pNIC : {vmnic0(a), vmnic1(s)}

PCI location :

Physical switch : vmnic0

ESXname : xxx.x.xxx.xxx

Portgroup : virtualmachines

VLANid : 0

pNIC : {vmnic2(a), vmnic3(s)}

PCI location :

Physical switch : vmnic2

0 Kudos
LucD
Leadership
Leadership
Jump to solution

1) The fact that you get the same PCI location for two NICs can only be explained by the fact that you have a multi-port NIC on that ESX server.

Each port will be a different pNIC but the PCI location of all these pNICs will be the same since it concerns the same PCI card.

2) This is the script with the devID property

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}else{"CDP not configured"}}
			}
		}
		foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){
			if($s){
				$pNICStr += ($s + "(s)")
				$pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $a} | %{$_.Pci + "(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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

I ran this script,

1. The devID property for physical switch works perfect. It gives out FQDN of the switch. :smileygrin:

2. The PCI location is from a multi port nic and as per my knowledge the last two digit gives out the difference. Usually its documented like this 06:02.00 (a) 06:02.01 (s) for vmnic2, vmnic3. Is there some way to pull it out using this script? If this gets ok then this is the perfect script for my requirement.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

There was a bug in the line for the snatdby NICs.

I compared with $a where it should be $s.

This should now (finally) produce the correct results.

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}else{"CDP not configured"}}
			}
		}
		foreach($s in $pg.ComputedPolicy.NicTeaming.NicOrder.StandbyNic){
			if($s){
				$pNICStr += ($s + "(s)")
				$pciStr += ($esx.Config.Network.Pnic | where {$_.Device -eq $s} | %{$_.Pci + "(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

0 Kudos
Sureshadmin
Contributor
Contributor
Jump to solution

Luc,

PCI location values are now perfect. Thanks a lot.

Just one more last clarification, just now i noticed the Physical switch value output from the script is like given below,

Physical switch : abcd-1234.xxxx.com

But my requirement is the values should come for active and standby nics, like given below,

abcd-1234.xxxx.com (a), xyza-1234.xxxx.com (s)

The main purpose of this script is to check redundancy of the esx network. So need to know whether active and standby nics are connected to different physical switch.

Can you please help?

0 Kudos
kwharrisit
Contributor
Contributor
Jump to solution

Luc,

Maybe there is no way to get the property that I was looking for, but in the VI client, if you go to the network adapter and highlight it, it will report the obsserved VLAN(s) for the port the nic is plugged into. I was thinking that it's picking that up from the CDP and thats why I thought I could see it via script. My intention would be to run this script against all of our clusters as an audit tool showing not only the proper nic and portgroup settings, but also the observed vlans. Many times we configure the servers correctly, but the network team missing adding a particular VLAN when trunking the port.

Also , is there any way to push the results into a sortable spreadsheet or table ?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, this version will also indicate the active and standby status.

And it will export the data to a CSV file.

Get-VMHost | %{ 
	$esxImpl = $_
	$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)"}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)"}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}}
	}
} | Export-Csv "C:\Nic-Info.csv" -NoTypeInformation -UseCulture

Which field in the CDP form in the vSphere client do you want to see ?

I'm afraid I don't have CDP available on my test system.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
kwharrisit
Contributor
Contributor
Jump to solution

Luc,

it's not in CDP , it shows up on the poperties page for the nic itself

under observed IP ranges, it will tell me the range and VLANs visible for that nic. I can then take those to verify that they are listed as expected.

thanks for the csv... man that looks slick!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The QueryNetworkHint method doesn't only return CDP information but also these IP ranges you see in the vSphere client.

This produces the values (with the additionl (a) or (s) indication.

Get-VMHost | %{ 
	$esxImpl = $_
	$esx = $esxImpl | Get-View
	$netSys = Get-View $esx.ConfigManager.NetworkSystem
	foreach($pg in $esx.Config.Network.Portgroup){
		$pNICStr = @()
		$pciStr = @()
		$cdpStr = @()
		$iprange = @()
		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)
				$iprange += $cdpInfo[0].Subnet | %{$_.IpSubnet + " (VLAN " + $_.VlanId + ")(a)"}
				$cdpStr += &{if($cdpInfo[0].connectedSwitchPort){$cdpInfo[0].connectedSwitchPort.devId + "(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)
				$iprange += $cdpInfo[0].Subnet | %{$_.IpSubnet + " (VLAN " + $_.VlanId + ")(s)"}
				$cdpStr += &{if($cdpInfo[0].connectedSwitchPort){$cdpInfo[0].connectedSwitchPort.devId + "(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="IP range + VLAN";E={$iprange}},
		@{N="pNIC";E={$pNICStr}},
		@{N="PCI location";E={$pciStr}},
		@{N="Physical switch";E={$cdpStr}}
	}
} | Export-Csv "C:\Nic-Info.csv" -NoTypeInformation -UseCulture

But the output becomes rather cluttered in the CSV file.

Any suggestions how you would want to present this in the CSV file ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Noticed that the two sub-threads became a bit mixed up in the script.

This is the script with the devIds with the active/standby indication.

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)"}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)"}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

0 Kudos
kwharrisit
Contributor
Contributor
Jump to solution

Luc... man youre good... I have an issue though... i did a copy of the last script you amended and I notce the export to csv is missing. I tried to add it back in at the end of the script but now i get an error that an empty pipe object is not allowed.

0 Kudos