There are multiple ways you can get the localhost name in PowerShell. You can use environment variables like $env:computername to get the localhost name in PowerShell. Here are some options for your
1 2 3 4 5 6 7 8 9 10 11 |
## Get localhost name using PowerShell $env:computername ## Or [System.Net.Dns]::GetHostName() ## Or Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name ## Or (latest version) [Environment]::MachineName |