Hello,<\/p>\n
I found the following script and it fits my needs almost perfectly except when it cannot find a hostname it does not notate it, I am a complete and utter powershell noob so if anyone can help modify this so it notates on the output file when it cannot find a hostname that would be amazing!<\/p>\n
thank you,<\/p>\n
Get-Content C:\\IP_Address.txt | ForEach-Object {([system.net.dns]::GetHostByAddress($_)).hostname >> c:\\hostname.txt}\n<\/code><\/pre>","upvoteCount":4,"answerCount":6,"datePublished":"2014-12-05T18:38:31.000Z","author":{"@type":"Person","name":"jonzie1957","url":"https://community.spiceworks.com/u/jonzie1957"},"acceptedAnswer":{"@type":"Answer","text":"$addresses = Get-Content C:\\IP_Address.txt\n\n$output = ForEach($address in $addresses){\n Try{\n $hostname = ([system.net.dns]::GetHostByAddress($_)).hostname\n }\n Catch {\n $hostname = 'Unresolved'\n }\n New-Object -TypeName PSObject -Property @{\n 'IP' = $address\n 'Hostname' = $hostname\n }\n}\n\n$output | Export-Csv -NoTypeInformation -Path \"c:\\out.csv\"\n<\/code><\/pre>\n+1 to Gary’s suggestion.<\/p>\n
Here is how to go about what you want to do in Powershell.<\/p>","upvoteCount":3,"datePublished":"2014-12-05T18:49:37.000Z","url":"https://community.spiceworks.com/t/powershell-script-assistance/362197/4","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hello,<\/p>\n
I found the following script and it fits my needs almost perfectly except when it cannot find a hostname it does not notate it, I am a complete and utter powershell noob so if anyone can help modify this so it notates on the output file when it cannot find a hostname that would be amazing!<\/p>\n
thank you,<\/p>\n
Get-Content C:\\IP_Address.txt | ForEach-Object {([system.net.dns]::GetHostByAddress($_)).hostname >> c:\\hostname.txt}\n<\/code><\/pre>","upvoteCount":4,"datePublished":"2014-12-05T18:38:31.000Z","url":"https://community.spiceworks.com/t/powershell-script-assistance/362197/1","author":{"@type":"Person","name":"jonzie1957","url":"https://community.spiceworks.com/u/jonzie1957"}},{"@type":"Answer","text":"Hi Jonze,<\/p>\n
Could you do me a favor and edit your post and use the code button for your PowerShell code? It makes reading it a lot easier. Thanks!<\/p>\n