best way to use the nslookup command on Windows to retrieve IP addresses for a list of hostnames.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 06:19 AM
Hi Friends,
As part of Discovery implementation and support work, we often need to verify the correctness of device hostnames or IP addresses. To reduce dependency on the Network and Servers teams, I created a PowerShell script for validation.
Note:copy all the hostnames in hostnmaes,txt file and save it in a folder then open powershell make sure to pipeline the path where the file and execute the following code. it worked for me... 🙂
# Initialize the output file with headers
"Hostname,IPAddress" | Out-File -FilePath output.csv -Encoding UTF8
# Read hostnames and resolve
Get-Content hostnames.txt | ForEach-Object {
$hostname = $_.Trim()
try {
$rec = Resolve-DnsName -Name $hostname -Type A -ErrorAction Stop
foreach ($r in $rec) {
"$hostname,$($r.IPAddress)" | Out-File -FilePath output.csv -Append -Encoding UTF8
}
} catch {
"$hostname,Could not resolve" | Out-File -FilePath output.csv -Append -Encoding UTF8
}
}
Hope this helps for to you, you can mark this respectively.
# Discovery # CMDB # ITOM
- Labels:
-
Discovery
-
Service Mapping