PowerTip: Use PowerShell to Get Computer Name


Summary: Use Windows PowerShell to get your computer name.

Hey, Scripting Guy! Question How can I use Windows PowerShell to easily retrieve my computer name?

Hey, Scripting Guy! Answer Use the environmental variable ComputerName:

$env:computername

Comments (3)

  1. Andrew says:

    A shorter alternative:
    Hostname

  2. robincm2 says:

    A longer alternative (using WMI):
    (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name

  3. PM says:

    get-childitem -path env:computername

Skip to main content