well, thank you.
you just pointed out the issue,
I was not clearing the IP address and the mac address Arrays for the primary ip address list.
thank you
Not sure what the issue is, your code in fact does that when more than 1 vNIC is present.
if (-not([String]::IsNullOrWhiteSpace($PrimaryIPAddress))) {
$PrimaryIPAddress = $PrimaryIPAddress -replace "([a-f0-9:]+:)+[a-f0-9]+", ""
$PrimaryIPAddress = $PrimaryIPAddress.trim()
}
elseif ([String]::IsNullOrWhiteSpace($PrimaryIPAddress)) {
$PrimaryIPAddress = "NULL"
}
if ($PrimaryIPAddress.Count -gt 1) {
Write-Host "More than one IP" -BackgroundColor Red
foreach ($IP in $PrimaryIPAddress) {
if ([String]::IsNullOrWhiteSpace($PrimaryIPAddressList)) {
$PrimaryIPAddressList += $IP
}
else { $PrimaryIPAddressList += "|" + $IP }
}
$PrimaryIPAddress = $PrimaryIPAddressList | Out-String
}
Similar for the MAC address.
Also I don't really understand what the purpose of the following line is
$PrimaryIPAddress = ($vm | Where-Object { $_.ExtensionData.Config.InstanceUuid -eq $InstanceUuid -and $_.ExtensionData.Config.Uuid -eq $VMUUID }).Guest.Ipaddress
When a VM has multiple vNICs, it can have multiple IP and MAC addresses.
If you mean by "Primary IP Address" the IP address of 'Network adapter 1', you could replace the $PrimaryIPAddress and $MacAddress code with
$primaryNIC = $vm.ExtensionData.Config.Hardware.Device | Where-Object { $_ -is [VMware.Vim.VirtualEthernetCard] -and $_.DeviceInfo.Label -eq 'Network adapter 1' }
$MacAddress = $primaryNIC.MacAddress
$PrimaryIPAddress = $vm.Guest.Nics.where{$_.MacAddress -eq $MacAddress}.IpAddress[0]
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
maybe a bit not for this topic but RVtools will give you a full excel report with IP and MAC
well, thank you.
you just pointed out the issue,
I was not clearing the IP address and the mac address Arrays for the primary ip address list.
thank you