VMware Host Network Info by alanrenouf 3 years ago
View followups from alanrenouf | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/855"></script>download | new post
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
- Connect-VIServer MYVISERVER
- $filename = "c:\DetailedNetworkInfo.csv"
- Write "Gathering VMHost objects"
- $vmhosts = Get-VMHost | Sort Name | Where-Object {$_.State -eq "Connected"} | Get-View
- $MyCol = @()
- foreach ($vmhost in $vmhosts){
- $ESXHost = $vmhost.Name
- Write "Collating information for $ESXHost"
- $networkSystem = Get-view $vmhost.ConfigManager.NetworkSystem
- foreach($pnic in $networkSystem.NetworkConfig.Pnic){
- $pnicInfo = $networkSystem.QueryNetworkHint($pnic.Device)
- foreach($Hint in $pnicInfo){
- $NetworkInfo = "" | select-Object Host, PNic, Speed, MAC, DeviceID, PortID, Observed, VLAN
- $NetworkInfo.Host = $vmhost.Name
- $NetworkInfo.PNic = $Hint.Device
- $NetworkInfo.DeviceID = $Hint.connectedSwitchPort.DevId
- $NetworkInfo.PortID = $Hint.connectedSwitchPort.PortId
- $record = 0
- Do{
- If ($Hint.Device -eq $vmhost.Config.Network.Pnic[$record].Device){
- $NetworkInfo.Speed = $vmhost.Config.Network.Pnic[$record].LinkSpeed.SpeedMb
- $NetworkInfo.MAC = $vmhost.Config.Network.Pnic[$record].Mac
- }
- $record ++
- }
- Until ($record -eq ($vmhost.Config.Network.Pnic.Length))
- foreach ($obs in $Hint.Subnet){
- $NetworkInfo.Observed += $obs.IpSubnet + " "
- Foreach ($VLAN in $obs.VlanId){
- If ($VLAN -eq $null){
- }
- Else{
- $strVLAN = $VLAN.ToString()
- $NetworkInfo.VLAN += $strVLAN + " "
- }
- }
- }
- $MyCol += $NetworkInfo
- }
- }
- }
- $Mycol | Sort Host, PNic | Export-Csv $filename -NoTypeInformation
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository