Given below are three methods (there could be more) of determining your Hostname in PowerShell:

METHOD 1:

# Fastest method
PS C:\> $env:COMPUTERNAME

METHOD 2:

# Slowest method
PS C:\> $(Invoke-Expression hostname)

METHOD 3:

PS C:\> [System.Net.Dns]::GetHostName()

VN:F [1.9.22_1171]
Rating: +6 (from 6 votes)