Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions Links


SQL Server DBA Jobs

How to get FQDN of multiple servers with Powershell

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 :





$myfile = New-Object System.IO.StreamReader -Arg "C:\servers.txt"

while ($svr = $myfile.ReadLine()) {



Sample output :

HostName                                Aliases                                 AddressList
--------                                -------                                 -----------           {}                                      {}           {}                                      {}


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 

Author: Tom Collins (


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.


Post a comment on How to get FQDN of multiple servers with Powershell | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer