I have a text file with hostnames and I am trying to find the list of IPs associated with these hostnames respectively and dump the output to a CSV , I am using the below powershell script but it gives me a lot of results but I only need the IP address.
Code:
$address = Get-Content ".\server_list.txt"
foreach ($i in $address) {
$i + "`n" + "=========================="
[System.Net.Dns]::GetHostAddresses($i)
}
it gives me output in below format.
hostname.com
==========================
Address : 12345678
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
IsIPv4MappedToIPv6 : False
IPAddressToString : 10.x.x.x
I only need the IPaddressToString value, any help would be appreciated.