How do you find the FQDN of the machine you’re using.  The simplest way is to combine a couple of environmental variables:


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)”}}


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

This entry was posted in Powershell Basics. Bookmark the permalink.

One Response to FQDN

  1. John B says:

    $env:USERDNSDOMAIN is the domain of the logged on user, worth bearing in mind if you’re running it with an account from a trusted domain.

    I ended up using the third option when I hit this issue.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s