PowerShell script to find Active Directory Fully Qualified Domain Name (FQDN)

Here is a PowerShell script that you can use to get the fully qualified domain name (FQDN) for the active directory domain in your environment, you will need to run this script from a computer that is joined to the AD domain.



# Import the ActiveDirectory module

Import-Module ActiveDirectory


# Get the domain name

$domainName = (Get-ADDomain).Name


# Get the domain DNS suffix

$domainSuffix = (Get-WmiObject Win32_NetworkAdapterConfiguration | Where {$_.IPEnabled}).DNSDomain


# Output the FQDN

Write-Output "FQDN: $domainName.$domainSuffix"


This script first imports the ActiveDirectory module, which contains the cmdlet Get-ADDomain that is used to retrieve the domain name. Then, it uses the Get-WmiObject cmdlet to get the DNS domain suffix for the domain from the Win32_NetworkAdapterConfiguration WMI class. Finally, it combines the domain name and the DNS suffix to output the FQDN.


Note that this script assumes that the local computer is joined to an active directory domain. If it is not, then the Get-ADDomain cmdlet will not return any information and the FQDN will not be correctly calculated. In that case, you will need to provide the FQDN manually.


Was this helpful?

Yes No


Comments