PoshCode Logo PowerShell Code Repository

Get-ObservedIPRange (modification of post by Carter Shanklin view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1680"></script>download | new post

Get observed IP address ranges and VLAN IDs from an ESX host’s physical adapter. Sample use at the bottom.

  1. function Get-ObservedIPRange {
  2.         param(
  3.                 [Parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="Physical NIC from Get-VMHostNetworkAdapter")]
  4.                 [VMware.VimAutomation.Client20.Host.NIC.PhysicalNicImpl]
  5.                 $Nic
  6.         )
  7.  
  8.         process {
  9.                 $hostView = Get-VMHost -Id $Nic.VMHostId | Get-View -Property ConfigManager
  10.                 $ns = Get-View $hostView.ConfigManager.NetworkSystem
  11.                 $hints = $ns.QueryNetworkHint($Nic.Name)
  12.  
  13.                 foreach ($hint in $hints) {
  14.                         foreach ($subnet in $hint.subnet) {
  15.                                 $observed = New-Object -TypeName PSObject
  16.                                 $observed | Add-Member -MemberType NoteProperty -Name Device -Value $Nic.Name
  17.                                 $observed | Add-Member -MemberType NoteProperty -Name VMHostId -Value $Nic.VMHostId
  18.                                 $observed | Add-Member -MemberType NoteProperty -Name IPSubnet -Value $subnet.IPSubnet
  19.                                 $observed | Add-Member -MemberType NoteProperty -Name VlanId -Value $subnet.VlanId
  20.                                 Write-Output $observed
  21.                         }
  22.                 }
  23.         }
  24. }
  25.  
  26. # Example use:
  27. # Get-VMHost esx01a.vmworld.com | Get-VMHostNetworkAdapter | Where { $_.Name -eq "vmnic1" } | Get-ObservedIPRange
  28.  
  29. # Example output:
  30. #Device                 VMHostId               IPSubnet                               VlanId
  31. #------                 --------               --------                               ------
  32. #vmnic1                 HostSystem-host-102    10.91.245.128-10.91...                   2907
  33. #vmnic1                 HostSystem-host-102    10.91.244.133-10.91...                   2905
  34. #vmnic1                 HostSystem-host-102    10.91.243.253-10.91...                   2903
  35. #vmnic1                 HostSystem-host-102    10.91.246.11-10.91....                   2908
  36. #vmnic1                 HostSystem-host-102    10.91.246.129-10.91...                   2909

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.

Syntax highlighting:


Remember me