1

I have take ownership previously using this

$key  = 'HKLM:\SOFTWARE\MyKEY'
$acct = New-Object System.Security.Principal.NTAccount("Administrators")
$acl = Get-ACL $key
$acl.SetOwner($acct)
Set-ACL -Path $key -ACLObject $acl

But when I tried to change the Access to READ with this, it creates a new ACL while the original one is still there. How do I alter the original one and how do I do this for all of its subkeys as well ? Can anyone please shed some light ?

$acl = get-acl 'HKLM:\SOFTWARE\MyKEY'
$rule = New-Object System.Security.AccessControl.RegistryAccessRule("Users","FullControl","ContainerInherit,ObjectInherit","None","Allow")
$acl.SetAccessRule($rule)
$acl | Set-Acl -Path 'HKLM:\SOFTWARE\MyKEY'
2
  • 1
    Do you meen $acl.AddAccessRule($rule) ? Commented Mar 18, 2024 at 15:23
  • I just want to change/update the existing one, but the script above creates a new one. And I have tested your suggestion, it does the same thing. Commented Mar 18, 2024 at 17:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.