Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New-Item recursive registry keys

With PowerShell you can run a command like this

ni c:/foo/bar -type directory

and it will create foo and bar as necessary. However if you run

ni hklm:software/classes/firefoxhtml/shell/edit/command -type directory

all keys but the last must exist or an error will be generated. Can PowerShell generate the parent keys as needed?

like image 390
Zombo Avatar asked Feb 14 '14 02:02

Zombo


People also ask

How do I query a registry key in PowerShell?

One of the easiest ways to find registry keys and values is using the Get-ChildItem cmdlet. This uses PowerShell to get a registry value and more by enumerating items in PowerShell drives. In this case, that PowerShell drive is the HKLM drive found by running Get-PSDrive .


1 Answers

I was just missing the -force parameter

New-Item hklm:software/classes/firefoxhtml/shell/edit/command -Force

Using -Force will also remove everything under the key if it already exists so a better option would be

if(!(Test-Path $path)){
    New-Item $path -Force;
}
like image 53
Zombo Avatar answered Sep 20 '22 22:09

Zombo