Menu Close

How to determine hostname using PowerShell

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)
Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *