Get-ObservedIPRange by Carter Shanklin 23 months ago (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.
- function Get-ObservedIPRange {
- param(
- [Parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="Physical NIC from Get-VMHostNetworkAdapter")]
- [VMware.VimAutomation.Client20.Host.NIC.PhysicalNicImpl]
- $Nic
- )
- process {
- $hostView = Get-VMHost -Id $Nic.VMHostId | Get-View -Property ConfigManager
- $ns = Get-View $hostView.ConfigManager.NetworkSystem
- $hints = $ns.QueryNetworkHint($Nic.Name)
- foreach ($hint in $hints) {
- foreach ($subnet in $hint.subnet) {
- $observed = New-Object -TypeName PSObject
- $observed | Add-Member -MemberType NoteProperty -Name Device -Value $Nic.Name
- $observed | Add-Member -MemberType NoteProperty -Name VMHostId -Value $Nic.VMHostId
- $observed | Add-Member -MemberType NoteProperty -Name IPSubnet -Value $subnet.IPSubnet
- $observed | Add-Member -MemberType NoteProperty -Name VlanId -Value $subnet.VlanId
- Write-Output $observed
- }
- }
- }
- }
- # Example use:
- # Get-VMHost esx01a.vmworld.com | Get-VMHostNetworkAdapter | Where { $_.Name -eq "vmnic1" } | Get-ObservedIPRange
- # Example output:
- #Device VMHostId IPSubnet VlanId
- #------ -------- -------- ------
- #vmnic1 HostSystem-host-102 10.91.245.128-10.91... 2907
- #vmnic1 HostSystem-host-102 10.91.244.133-10.91... 2905
- #vmnic1 HostSystem-host-102 10.91.243.253-10.91... 2903
- #vmnic1 HostSystem-host-102 10.91.246.11-10.91.... 2908
- #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.
PowerShell Code Repository