<p>Here&#8217;s how you can get the list of IP addresses, FQDN and Ping status with a simple Powershell server list script.</p>
<p>For a start create a servers.txt file in C:\temp folder with the list of servers you would like to resolve. You need to put one server per line. You also need to have Microsoft Excel installed on the system since the result will be exported to .csv file.</p>
<p><strong>C:\temp\servers.txt</strong></p>
<p><strong>servers.txt</strong> example:</p>
<p><em>hostname</em><br />
<em>hostname2</em><br />
<em>hostname3</em></p>
<p>Now create a new text file and rename it to <strong>serverlist.ps1</strong></p>
<pre>$counter = 1 
$comps = get-content C:\TEMP\servers.txt 
$dnsResults = "C:\TEMP\IP address.csv" 
 
function get-dnsres{ 
foreach ($comp in $comps) { 
$TempIP = ([system.net.dns]::GetHostAddresses($comp)) | select IPAddressToString 
 
$status = "Processing system {0} of {1}: {2}" -f $counter,$comps.Count,$comp 
Write-Progress 'Resolving DNS' $status -PercentComplete ($counter/$comps.count * 100) 
$counter++ 
$comp | 
select @{Name='ComputerName';Expression={$comp}}, ` 
@{Name='ResolvesToIP';Expression={[system.net.dns]::GetHostAddresses($comp)}}, ` 
@{Name='IPResolvesTo';Expression={([system.net.dns]::GetHostEntry($TempIP.IPAddressToString)).HostName}}, ` 
@{Name='PingStatus'; Expression={ ` 
if ((get-wmiobject -query "SELECT * FROM Win32_PingStatus WHERE Address='$comp'").statuscode -eq 0) {'Host Online'} ` 
elseif ((get-wmiobject -query "SELECT * FROM Win32_PingStatus WHERE Address='$comp'").statuscode -eq 11003) {'Destination Host Unreachable'} ` 
elseif ((get-wmiobject -query "SELECT * FROM Win32_PingStatus WHERE Address='$comp'").statuscode -eq 11010) {'Request Timed Out'} ` 
elseif ((get-wmiobject -query "SELECT * FROM Win32_PingStatus WHERE Address='$comp'").statuscode -eq $Null) {'NoDNS'} 
} 
} 
} 
} 
 
get-dnsres | export-csv $dnsResults -notypeinformation 
invoke-item $dnsResults 
</pre>
<p>Save the script to the same folder at C:\temp.</p>
<p>Before you&#8217;ll be able to run the script you will have to enable execution policy on your system:</p>
<p>Start the Powershell in elevated mode (Run as Administrator) and run the following command:</p>
<p><strong>Set-ExecutionPolicy RemoteSigned</strong></p>
<p>Now run the Powershell script by using this command:</p>
<p><strong>powershell -noexit &#8220;&; &#8220;&#8221;C:\temp\serverlist.ps1&#8243;&#8221;&#8221;</strong></p>
<p>You should get the results on screen and also saved to <strong>C:\temp\IP address.csv</strong> file.</p>
<p><a href="https://www.wincert.net/wp-content/uploads/2016/01/server-list-script.png" rel="attachment wp-att-1637"><img class="alignnone size-full wp-image-1637" src="https://www.wincert.net/wp-content/uploads/2016/01/server-list-script.png" alt="server list script" width="644" height="148" /></a></p>
<p>Please feel free to comment if you have any advices regarding this simple server list script.</p>
<p>There are also some third-party free tools available for download like:</p>
<p><a href="http://www.nirsoft.net/utils/fastresolver.html" target="_blank">NirSoft FastResolver</a><br />
<a href="http://www.ks-soft.net/ip-tools.eng/" target="_blank">IP Tools</a></p>

How to get an IP address from a server list script
