Listing the full Windows machine name including domain

I was searching the other day for a way to print out the fully qualified domain name of a machine I was working on and finally found this solution:


which returns:


for that machine. Wonderful.

This may fail however if your users are in a different domain than the machine. %USERDNSDOMAIN% will return the user’s domain, not the machine’s domain. This command will return the correct answer in this case:

C:\> FOR /F "tokens=2" %i in ('systeminfo ^| find /i "Domain"') do echo %computername%.%i

Note:  use double % for %i if using this in a batchfile. e.g. %%i

There are other methods that don’t use systeminfo (which slows down the process), but they are more than one line commands. You can google search to find more robust alternative batch code samples.

I know this info is available via other screens, but I needed it via dos command line for a bit of testing and programming I was doing at the time. Hey, works for me.