2 Methods to Get Hostname on Windows

2 Methods to Get Hostname on Windows

A hostname is a unique identifier that is assigned to a device (host) which connected to the network. It allows to differentiate one device from another on a specific network. This tutorial shows 2 methods to get hostname on Windows.

Method 1 - CMD

On Windows, the hostname command can be used for displaying hostname. Run command without any arguments:

hostname

Output example:

john-pc

Method 2 - PowerShell

The hostname command can be used in PowerShell as well. There are another way. The System.Net.DNS class provides GetHostName method to get hostname.

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

Leave a Comment

Cancel reply

Your email address will not be published.