Quick Hits: Getting the Local Computer Name

I’ve had a few emails and questions about the best way to get the hostname of the local computer that you are currently logged into and felt that a quick (and I mean quick Smile) post here would be worthwhile.

Using WMI or the CIM cmdlets, you can pull the information from just about any class as there is the __Server property which gives you the name, or you can make of the PSComputername property (which is just an alias to __Server thanks to a type file). Here is one such example:

Get-WMIObject –Class Win32_Bios | Select PSComputername, __Server


A more simple approach is making use of a legacy command, hostname.exe which will present you with the local machine’s computername.


There are also environmental variables that you can make use of to get this information like COMPUTERNAME.



That’s it! Like I said, this was short and sweet. Do you know an other ways to display the hostname of your local machine? Comment with them below!

This entry was posted in powershell and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s