Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pull an inventory of all ESXi VTEP virtual interfaces from all connected vCenter Servers
function Get-VMHostVtepInterface {
<#
.SYNOPSIS
Gather VTEP interface inventory from all ESXi hosts
.DESCRIPTION
Gather VTEP interface inventory from all ESXi hosts.
This function was written with scale and speed in mind. It pull a host inventory using API calls and then unrolls API properties and
assigned them to a PSCustomObject.
.OUTPUTS
[System.Management.Automation.PSCustomObject]
.NOTES
Author: Kevin Kirkpatrick
URL: https://github.com/vScripter
Email: Kevin(at)vmotioned(dot)com
Version: 1.0
Updated: 8/10/16
Update Notes: 8/10/16
#>
[OutputType([System.Management.Automation.PSCustomObject])]
[CmdletBinding()]
param()
BEGIN {
Write-Verbose -Message "[Get-VMHostVtepInterface] Gathering VMHost Inventory"
try {
$vmHostInventory = $null
$vmHostInventory = Get-View -ViewType HostSystem -Property Name,Config -ErrorAction 'Stop'
} catch {
throw "[Get-VMHostVtepInterface][ERROR] Could not gather VMHost inventory using 'Get-View'. $_"
} # end try/catch
} # end BEGIN block
PROCESS {
foreach ($vmHost in $vmHostInventory) {
$vtepInterfaceQuery = $null
$vtepInterfaceQuery = $vmHost.Config.Network.Vnic | Where-Object {$_.Spec.NetStackInstanceKey -eq 'vxlan'}
$vmHostName = $null
$vmHostName = $vmHost.Name
[uri]$vCenter = $null
$vCenter = $vmHost.Client.ServiceUrl
Write-Verbose -Message "[Get-VMHostVtepInterface] Gathering VTEP VMkernel Interfaces for host {$vmHostName}"
foreach ($vtep in $vtepInterfaceQuery) {
$objVtepInt = @()
$objVtepInt = [PSCustomObject] @{
VMHost = $vmHostName
Interface = $vtep.Device
MacAddress = $vtep.Spec.Mac
IPv4Address = $vtep.Spec.Ip.IpAddress
SubnetMask = $vtep.Spec.Ip.SubnetMask
DHCP = $vtep.Spec.Ip.Dhcp
MTU = $vtep.Spec.Mtu
TsoEnabled = $vtep.Spec.TsoEnabled
NetworkStack = $vtep.Spec.NetStackInstanceKey
PinnedPnic = $vtep.Spec.PinnedPnic
vCenter = $vCenter.Host
} # end $objVtepInt
$objVtepInt
} # end foreach $vtep
} # end foreach $vmHost
} # end PROCESS block
END {
Write-Verbose -Message "[Get-VMHostVtepInterface] Processing complete"
} # end END block
} # end function Get-VMHostVtepInterface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.