Output server IP details to text file

Reading Time: < 1 minute

The below script will allow you to output ip details for multiple servers on a network.

You will need powershell v2 installed and the PsExec executable

Copy & paste the following into Powershell amending the paths as required.

$inputfile = ‘C:\serverslist.txt’  #this is the file containing the list of server host names, one per line

$outputfolder = ‘C:\outputfolder\’  #this is the folder where the output text files will be stored

set-alias psexec ‘C:\PsExec.exe’ #this is the path to the free Sysinternals PsExec tool, available from http://technet.microsoft.com/en-us/sysinternals/bb897553

$servers=Get-Content $inputfile #get list of server hostnames

$serverscount = $servers.count;$i=0 #set values for progress counter

foreach ($server in $servers) {  #loop systematically through each server in the intput file

$i++  #increment progress counter   

Write-Progress -Activity “Checking servers for IPconfig and static route info” -Status “Querying:” -percentcomplete ((($i-1) / $serverscount)*100) -CurrentOperation “$server ($i of $serverscount)”  #display progress to the end user

$serverUNC = “\\” + $server  #PsExec requires server names to have \\ in front of them

$ipconfigoutput = & PsExec $serverUNC ipconfig /all #Connect to remote server using PsExec and run ipconfig /all

$routeprintoutput = & PsExec $serverUNC route print #Connect to remote server user PsExec and run route print

$outputfilename = $outputfolder+$server+”.txt”  #generate file name based on server name

($ipconfigoutput + $routeprintoutput) | out-file $outputfilename #output data to text file

}

Thanks to Nadeem Ahmed for providing this script

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.