How are [environment] and $env different in powershell?
try using
[environment]::machinename
$env
is directly bound to enviroment variable
[environment]
is a .net class
When you use [environment]::computername
you are in fact using .NET code in Powershell. So reading the documentation for the Environment Class reveals that you should use [environment]::machinename
instead.
$env
is a shortcut for the environment PSDrive.
I don't know why Microsoft uses two different names here.
BTW: There are a lot more ways to get the computername, you could also e.g. use wmi: Get-WMIObject Win32_ComputerSystem | Select-Object -ExpandProperty name