How can I create a registry value and path leading to it in one line using PowerShell?
You can pipe the creation line to the New-ItemProperty
line as follows, but be aware that the -Force
flag on New-Item
will delete any pre-existing contents of the key:
New-Item 'HKCU:\Software\Policies\Microsoft\Windows\EdgeUI' -Force | New-ItemProperty -Name DisableHelpSticker -Value 1 -Force | Out-Null
Another way of simplifying PS registry handling is calling the .Net function SetValue() directly:
[microsoft.win32.registry]::SetValue("HKEY_CURRENT_USER\Software\Test", "Test-String", "Testing")[microsoft.win32.registry]::SetValue("HKEY_CURRENT_USER\Software\Test", "Test-DW", 0xff)
I didn't have any luck with @mschomm's answer for setting a DWORD value. Finally got this code to work for me:
$RegName = '2233969290'$RegPath = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Policies\Microsoft\FeatureManagement\Overrides\'$RegData = 0 Write-Output "Setting Registry Key" [microsoft.win32.registry]::SetValue($RegPath, $RegName, $RegData, [Microsoft.Win32.RegistryValueKind]::DWORD)