Problem
Find the default gateway on a list of remote servers.
Solution
Create a textfile with a list of servers you would like to query, use a new line for each server. If you have an OU of servers you would like to query you could use the following to create a text file with all computer accounts within an OU (requires Active Directory Module for Windows PowerShell).
Get-ADComputer -LDAPFilter "(name=*)" -SearchBase "OU=Servers,DC=domain,DC=local" | Select -expand name | Out-File -Encoding utf8 "\\server\share\Servers.txt"
This would create a textfile with every computer account in the “Servers” OU on domain.local.
I tend to put a “dummy” line at the top of the text file as PSEXEC has issues with the first entry.
Now use PSEXEC to execute the following, don’t forget to run the command prompt as administrator (using an account with the required permissions on the remote servers).
psexec @c:\Serverlist.txt ipconfig /all | findstr "Default Gateway Host" >> c:\Servergateways.txt
…and here’s the final result.
The post Get Default Gateway from List of Remote Servers appeared first on The Sysadmins.