Output issue - CSV


I have the code at the bottom of this message. Ideally, I want the code to take a list of domain names, and output the domain name next to the IP address it resolves to in a CSV file. So output needs to be:

  • domain
  • IP it's resolving to
I have the following code which I can get to run but no idea how to resolve what I need to a csv - however you need to treat me like a child with this:

$names=get-content “C:\users\desktop\addresses.txt”
foreach($name in $names) {
resolve-dnsname $name}

Any help greatly appreciated



welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!

Then … when you post code, error messages, sample data or console output format it as code, please.

Here you can read how that works: Guide to Posting Code.

You can go back and edit your existing post. You don’t have to create a new one. :wink:

Thanks in advance.

The output you get from Resolve-DnsName depends pretty much on the input. If you provide “internal” addresses the output looks different to when you provide internet addresses like “www.bing.com” for example. In the easiest case something like this could be enough:

$DomainNameList = Get-Content -Path 'C:\users\desktop\addresses.txt'
$Result =
foreach($DomainName in $DomainNameList) {
    Resolve-DnsName -Name $DomainName |
        Select-Object -Property Name,IPAddress

If you need you can pipe this to Export-Csv for further steps. :wink:

And as always the recommendation to read the help completely including the examples to learn how to use the cmdlets your about to use. :wink:


That worked a treat… Olaf you are a god amongst snowmen