This script will output IP & Hostname in a CSV and will give a warning in the CLI upon failure (no DNS Record). Is it possible to also output the Failures to the CSV with the hostname defaulted to “Null”?<\/p>\n
Essentially I want a complete CSV after a bulk DNS lookup including the failures. Any information for a PS Newbie will be appreciated.<\/p>\n
get-content \"C:\\Users\\xxx\\yyy\\ips.txt\" | foreach-object {\n $ipAddress = $_\n try {\n [System.Net.Dns]::GetHostEntry($ipAddress) | select-object `\n @{Name = \"IPAddress\"; Expression = {$ipAddress}},\n HostName\n }\n catch [System.Management.Automation.MethodInvocationException] {\n write-warning \"IP did not resolve - $ipAddress\"\n }\n} | export-csv \"C:\\Users\\xxx\\yyy\\ReverseLookup.csv\" -notypeinformation\n<\/code><\/pre>","upvoteCount":3,"answerCount":3,"datePublished":"2020-03-16T17:09:26.000Z","author":{"@type":"Person","name":"edwardrobinson6","url":"https://community.spiceworks.com/u/edwardrobinson6"},"suggestedAnswer":[{"@type":"Answer","text":"
Advertisement
This script will output IP & Hostname in a CSV and will give a warning in the CLI upon failure (no DNS Record). Is it possible to also output the Failures to the CSV with the hostname defaulted to “Null”?<\/p>\n
Essentially I want a complete CSV after a bulk DNS lookup including the failures. Any information for a PS Newbie will be appreciated.<\/p>\n
get-content \"C:\\Users\\xxx\\yyy\\ips.txt\" | foreach-object {\n $ipAddress = $_\n try {\n [System.Net.Dns]::GetHostEntry($ipAddress) | select-object `\n @{Name = \"IPAddress\"; Expression = {$ipAddress}},\n HostName\n }\n catch [System.Management.Automation.MethodInvocationException] {\n write-warning \"IP did not resolve - $ipAddress\"\n }\n} | export-csv \"C:\\Users\\xxx\\yyy\\ReverseLookup.csv\" -notypeinformation\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2020-03-16T17:09:26.000Z","url":"https://community.spiceworks.com/t/dns-lookup-export-to-csv-including-failures/755522/1","author":{"@type":"Person","name":"edwardrobinson6","url":"https://community.spiceworks.com/u/edwardrobinson6"}},{"@type":"Answer","text":"sure, you can create a custom object and feed that with the fail / pass info.<\/p>","upvoteCount":0,"datePublished":"2020-03-16T17:22:59.000Z","url":"https://community.spiceworks.com/t/dns-lookup-export-to-csv-including-failures/755522/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"
In my experience exports by default dump everything in a CSV file. You have to then open the csv and clean it up.<\/p>","upvoteCount":0,"datePublished":"2020-03-22T17:12:34.000Z","url":"https://community.spiceworks.com/t/dns-lookup-export-to-csv-including-failures/755522/3","author":{"@type":"Person","name":"klonkhead","url":"https://community.spiceworks.com/u/klonkhead"}}]}}