does anyone know how or if it's possible to change permissions on some keys in subtree but exclude a couple? when each key has a different name? example; hkey_local_machine\software\blahh\ key1blip key2blop key3boo key4blag key5blee change permissions on key 1 & 2 but ignore / exclude 3,4 & 5 can this be done somehow?
Get-ChildItem is your friend. If your keys contain wildcards, you need to use a wildcard comparison operator like "-like" and "-notlike" instead of "-in" or "-notin" Use an array for the keys and use the Where-Object (?) cmdlet. This is not a working script, since I do not know the keys you need, but it's generally how I mass-remove keys based on criteria. Code: $path="\SOFTWARE\Microsoft\Windows\blahh\" [string[]]$subkeyArgs = @("key1", "key2", etc) Get-ChildItem HKLM:$path -Recurse -EA Stop | Get-ItemProperty -Name LocalPackage -EA SilentlyContinue | ? { $_.LocalPackage -in "*" + $subkeyArgs } | Set-ItemProperty -Name etc...