Hi,
I am getting IPv4 and IPv6 both using the below script. How can I get only IPv4 Addresses.
Please help.
$vm = Import-Csv -Path .\VMs.csv -UseCulture
$report = Get-VM $vm.Name | Get-NetworkAdapter |
Select-Object @{N="VM";E={$_.Parent.Name}},
@{N="NIC";E={$_.Name}},
@{N="Network";E={$_.NetworkName}},
MacAddress,
@{N='IP';E={
$vNIc = $_
($_.Parent.ExtensionData.Guest.Net | where { $_.MacAddress -eq $vNIc.MacAddress }).IPAddress -join ', '
}},
@{N='DNS';E={($_.Parent.ExtensionData.Guest.Net.DNSConfig).IPAddress -join ', '}}
$report | ft -auto
My bad, try with
$vNIc = $_
(($_.Parent.ExtensionData.Guest.Net | where { $_.MacAddress -eq $vNIc.MacAddress }).IPAddress | where{$_ -match '\.'}) -join ', '
}}, @{N='DNS';E={($_.Parent.ExtensionData.Guest.Net.DNSConfig).IPAddress -join ', '}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Add a Where-clause, something like this for example
$vNIc = $_
(($_.Parent.ExtensionData.Guest.Net | where { $_.MacAddress -eq $vNIc.MacAddress }).IPAddress | where{$_ -contains '.'}) -join ', '
}},
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I am getting IP field blank.
My bad, try with
$vNIc = $_
(($_.Parent.ExtensionData.Guest.Net | where { $_.MacAddress -eq $vNIc.MacAddress }).IPAddress | where{$_ -match '\.'}) -join ', '
}}, @{N='DNS';E={($_.Parent.ExtensionData.Guest.Net.DNSConfig).IPAddress -join ', '}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much LucD. That worked perfectly