Herschelle
Enthusiast
Enthusiast

command to retrieve visible networks for each vmnic

Jump to solution

Hello all,

We have on fairly regular basis "discussions" with our it comms brethren about the configuration of their switches / trunks etc when we have communications issues with VMs. More often than not, in our environment anyway, it turns out to be a misconfigured switch ports or trunks. So I am wondering if it is possible to report on the trunked networks that a pnic on an ESX server can see using PowerShell / VI Perl Toolkit.

To explain what I mean, In the VI Client I can click on a host -> configuration tab -> select network adapters. In the right hand pane it displays all the pnics in the host, to the right is the Networks column and this displays the networks that this pnic has visibility of, e.g. all the vlans that are trunked to it.

Can I get this information from one of the toolkits? Preference, well not my preference but the company i work for, is PowerShell.

I have had a look at the change log for VI Toolkit for windows 1.5 as well.

What I would like to be able to do is run a report across the cluster(s) to ensure all the pnics that are connected to the VM vSwitches can all see the same networks. In the same way you can do with the datastores / luns / port groups.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Based on the script below emulates the page from the VI client.

Write-Host "Device" "`t" "Speed" "`t`t" "Configured" "`t" "vSwitch" "`t" "Observed IP ranges" "`t`t" "WOL"

Get-VMHost | Sort-Object -property Name | Get-View | % {
	Write-Host "ESX : " $_.Name

	foreach($pnic in $_.Config.Network.Pnic){
		$device = $pnic.Device
		$speed = [string]($pnic.LinkSpeed.SpeedMb)
		if($pnic.LinkSpeed.Duplex){$speed += " Full"}
		foreach($vs in $_.Config.Network.Vswitch){
			foreach($pn in $vs.Pnic){
				if($pn -eq $pnic.Key){$vswitch = $vs.Name}
			}
		}
        $configured = ""
		if($pnic.Spec.LinkSpeed -eq $null){
		  $configured = "Negotiate"
		} 
		$netSys = Get-View $_.ConfigManager.NetworkSystem
		$IPrange = ""
		$hintinfo = $netSys.QueryNetworkHint($pnic.Device)
		foreach($pnicHintInfo in $hintinfo){
			foreach($pnicIPHint in $pnicHintInfo.subnet){
				$IPrange += $pnicIPHint.IpSubnet
				if($pnicIPHint.VlanId -ne 0){
				  $IPrange += (" (VLAN " + $pnicIPHint.VlanId + ")")
				}
				if($pnicHintInfo.Subnet.Count -gt 1){
				  $IPrange += ","
				}
			}
		}
		if($pnic.WakeOnLanSupported) {$WOL = "Yes"} else {$WOL = "No"}

		Write-Host $device "`t" $speed "`t" $configured "`t" $vswitch "`t" $IPrange "`t" $WOL
	}
}


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

View solution in original post

3 Replies
LucD
Leadership
Leadership

Based on the script below emulates the page from the VI client.

Write-Host "Device" "`t" "Speed" "`t`t" "Configured" "`t" "vSwitch" "`t" "Observed IP ranges" "`t`t" "WOL"

Get-VMHost | Sort-Object -property Name | Get-View | % {
	Write-Host "ESX : " $_.Name

	foreach($pnic in $_.Config.Network.Pnic){
		$device = $pnic.Device
		$speed = [string]($pnic.LinkSpeed.SpeedMb)
		if($pnic.LinkSpeed.Duplex){$speed += " Full"}
		foreach($vs in $_.Config.Network.Vswitch){
			foreach($pn in $vs.Pnic){
				if($pn -eq $pnic.Key){$vswitch = $vs.Name}
			}
		}
        $configured = ""
		if($pnic.Spec.LinkSpeed -eq $null){
		  $configured = "Negotiate"
		} 
		$netSys = Get-View $_.ConfigManager.NetworkSystem
		$IPrange = ""
		$hintinfo = $netSys.QueryNetworkHint($pnic.Device)
		foreach($pnicHintInfo in $hintinfo){
			foreach($pnicIPHint in $pnicHintInfo.subnet){
				$IPrange += $pnicIPHint.IpSubnet
				if($pnicIPHint.VlanId -ne 0){
				  $IPrange += (" (VLAN " + $pnicIPHint.VlanId + ")")
				}
				if($pnicHintInfo.Subnet.Count -gt 1){
				  $IPrange += ","
				}
			}
		}
		if($pnic.WakeOnLanSupported) {$WOL = "Yes"} else {$WOL = "No"}

		Write-Host $device "`t" $speed "`t" $configured "`t" $vswitch "`t" $IPrange "`t" $WOL
	}
}


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

View solution in original post

Herschelle
Enthusiast
Enthusiast

thanks, i will give that a go and let you know how it goes.

0 Kudos
Herschelle
Enthusiast
Enthusiast

Thankyou very much LucD, That is what I am looking for. I will do some manipulation of the output but at least now I have the data. Smiley Happy

0 Kudos