Grabbing ESXi Management IP & Serial Numbers

Needed to put a quick patchwerk script together to obtain the management IP and serials from multiple vCenters.

Add-PSSnapin vmware.vimautomation.core

$credentials = Get-Credential

function Get-VIHostInfo
{
    foreach($vmhost in get-vmhost)
    {
        $info = Get-VMHost -Name $vmhost.Name | Select Name,@{n="ManagementIP"; e={Get-VMHostNetworkAdapter -VMHost $_ -VMKernel | ?{$_.ManagementTrafficEnabled} | %{$_.Ip}}}
        $esxiHost = Get-VMHost $vmhost.Name | Get-EsxCli
        Write-Host $vmhost.Name","$esxiHost.hardware.platform.get().SerialNumber","$info.ManagementIP
    }
}

$arrVIServers = "" #Insert vCenter IPs here

foreach($server in $arrVIServers)
{
    Connect-VIServer -Server $server -Credential $credentials
    Get-VIHostInfo
    Disconnect-VIServer -Server $server -Force -Confirm:$false
}

Leave a Reply

Your email address will not be published. Required fields are marked *