How do I get the localhost name in PowerShell?
问题 How do I get the localhost (machine) name in PowerShell? I am using PowerShell 1.0. 回答1: You can just use the .NET Framework method: [System.Net.Dns]::GetHostName() also $env:COMPUTERNAME 回答2: Don't forget that all your old console utilities work just fine in PowerShell: PS> hostname KEITH1 回答3: Long form: get-content env:computername Short form: gc env:computername 回答4: All above questions are correct but if you want the hostname and domain name try this: [System.Net.DNS]::GetHostByName('')