Before Windows Server 2016, I was thinking that they are not the same is because of following:

  • hostname is a exe wrapper from MS, it returns full computer name, even it’s more than 15 characters
  • $env:computername is a var in PowerShell, it returns NetBIOSComputername which is limited in 15 characters

But today, I’m so wrong….


  • Container Host: Docker01-Gui
  • Container name:

By using following command:

We got result in Container Host:

We got result in Container itself:

As we can see above, “hostname.exe” and “[System.Net.Dns]::GetHostName()” are returning Container Host’name which is not the real value I think it should be…

I’m not sure if this is the expected value or a bug, but anyway, I’m going to use $env:computername to retrieve the local computername in the future.

How about you?