Question

I'm trying to add/edit the registry key with powershell:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment Name:Station Value: 2 Type: String

I was trying to do it with:

New-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" -Name "Station" -ItemType "String -Value "2" -force

However this just creates a subfolder named "Station" under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet001\Control\Session Manager\Environment with a name: "default" and a value: "2"

I don't understand one why it makes a key in the 001 CCS tab, and two why it makes it as a sub-folder instead of a key name. What am I missing here.

Was it helpful?

Solution

When using the registry provider, "Items" correspond to KEYS (i.e. "folders"), whereas "Item Properties" correspond to VALUES. So you want to use the New-ItemProperty cmdlet for this.

New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name 'Station' -Value '2' -PropertyType 'string'

You can view complete documentation on the registry provider by running Get-Help Registry.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top