12 January,2017 by Tom Collins
Question : I want to get the FQDN of 100 servers. How can I get these details, running one script and returning the FQDN
I’ve read the post SQL Server - Powershell - Get FQDN – Hostname and IP address which gives me the cmdlets for getting the FQDN - either hostname or ip address , but the post deals with one server
Answer: Once you’ve decided on which particular FQDN information you want to return – the post mentioned above has a few different options such as ip address or Hostname , then it’s just a matter of being able to read a list of servers, executing the code for every server.
This Powershell code will stream a list of servers from a text file , and then recover the FQDN from [System.Net.Dns]::GetHostByName cmdlet.
In the text file list the servers such as :
server1
server2
$myfile = New-Object System.IO.StreamReader -Arg "C:\servers.txt" while ($svr = $myfile.ReadLine()) { [System.Net.Dns]::GetHostByName($svr) } $myfile.close()
Sample output :
HostName Aliases AddressList
-------- ------- -----------
server1.mydomain.net {} {xx.xxx.xxx.xx}
server2.mydomain.net {} {xx.xxx.xxx.xx}
This example reads from a text file , but it could be adapted to read from an array or other input sources such as SQL server or Excel
Read More
Powershell Script – How to export Excel worksheet columns into a html file
SQL Server – Export Excel data to SQL Server with Powershell
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |