venerdì 12 giugno 2020

NSX-T - How to retrieve TEP IPs by PowerShell

Issue
Today I needed to quickly retrieve all the TEP IPs assigned by NSX-T (from an IP Pool) to the Hosts of a specific ESXi Cluster.

Solution
To do that, I wrote a powershell script, available below.
It is enough just replace the variables<VCENTER_FQDN_or_IP> with it's own vCenter (FQDN or IP) references and <CLUSTER_NAME> with the name of the Cluster where the ESXi Hosts are placed.
Connect-VIServer -Server <VCENTER_FQDN_or_IP> 

$hosts = Get-Cluster <CLUSTER_NAME> |Get-VMHost
$Report = @()
foreach($ESXi in $hosts){
  $tempModule=@{}
  $tempModule.Name = $ESXi.name
  $esxcli = get-vmhost $ESXi | Get-EsxCli
  $IPApp = $esxcli.network.ip.interface.ipv4.get("","vxlan")| Select @{N="IPv4Address";E={$_.IPv4Address}}
  $tempModule.IP = $($IPApp.IPv4Address)
  $temp = New-Object -TypeName PSObject -Property $tempModule
  $Report += $temp
} 
$Report | Select Name,IP | Sort-Object -Property Name | Out-Gridview
The script has been successfully tested on a production environment and on VMware' HOL as it is possible to see below.



That's it.

Nessun commento:

Posta un commento