In this tutorial, let me teach you how to get the Computer name in PowerShell. There are various options for “PowerShell get Computer name”.
Get Computer Name using .NET Framework’s Function
Using GetHostName() function of Dns class will simply get you the Hostname of the machine the function is executed from.
[System.Net.Dns]::GetHostName()
In the above Syntax, the GetHostName() that resides in the core .NET framework and the below result is displayed on invoking it.

Get Computer Name using PowerShell’s Environment Variable – Option 1
Another easiest way to get the Computer Name is to use the PowerShell’s environment variable $env. The syntax is;
$env:COMPUTERNAME
On running the above command, you will get the same result.

Get Computer/Host Name in PowerShell using Environment Variable – Option 2
The Keyword Environment in PowerShell can also be used to grab the Computer Name. The syntax is;
[Environment]::MachineName
And, there will not be any change in the Result too.

READ: More Topics on PowerShell?