I am stuck on a issue. I am trying to set user-environment variables using PowerShell:
[Environment]::SetEnvironmentVariable($key,$value,'User')
But when I look into the registry I can see the new entry is of type REG_SZ.
I would like it to be of type REG_EXPAND_SZ.
Can someone help me with this problem?
Use the
Microsoft.Win32namespace for Registry methods. To set the data type, use RegistryValueKind enumeration. Like so:User variables are located in
HKEY_CURRENT_USER\EnvironmentSystem variables are located in
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment