How do I get the localhost name in PowerShell? October 16, 2022 by Tarik You can just use the .NET Framework method: [System.Net.Dns]::GetHostName() also $env:COMPUTERNAME