Monthly Archive

FQDN

How do you find the FQDN of the machine you’re using. 

The simplest way is to combine a couple of environmental variables:

PS> "$env:COMPUTERNAME.$env:USERDNSDOMAIN"
SERVER02.MANTICORE.ORG

 

If you like using CIM (and who doesn’t) you can try this

PS> Get-CimInstance -ClassName Win32_ComputerSystem |
>> select @{N='FQDN'; E={"$($_.DNSHostName).$($_.Domain)"}}
>>

FQDN
----
server02.Manticore.org

 

This could easily be used for remote machines as well by adding the –ComputerName parameter to Get-CimInstance

 

If you want to go down the .NET route you have:

PS> [System.Net.Dns]::GetHostByName('').HostName
server02.Manticore.org

Comments are closed.