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)