How do I get the localhost name in PowerShell?

George2 picture George2 · Jul 23, 2009 · Viewed 211.5k times · Source

How do I get the localhost (machine) name in PowerShell? I am using PowerShell 1.0.

Answer

Strelok picture Strelok · Jul 23, 2009

You can just use the .NET Framework method:

[System.Net.Dns]::GetHostName()

also

$env:COMPUTERNAME