Define the registry path (modify to your specific registry key)$registryPath = "HKLM\SOFTWARE\Microsoft\SystemCertificates\Remote Desktop\Certificates"
Define the SYSTEM account (since we're targeting SYSTEM group)
$user = "NT AUTHORITY\SYSTEM" # SYSTEM account
Get the current ACL for the registry key
$acl = Get-Acl -Path "Registry::$registryPath"
Disable inheritance (this will copy current permissions but prevent new inheritance)
$acl.SetAccessRuleProtection($true, $true) # True: Protect (disable inheritance), True: Copy inherited rules
Create a deny access rule for FullControl for SYSTEM account
$denyRule = New-Object System.Security.AccessControl.RegistryAccessRule(
$user, "FullControl", "ContainerInherit,ObjectInherit", "None", "Deny"
)
Add the deny rule to the ACL
$acl.AddAccessRule($denyRule)
Apply the updated ACL to the registry key
Set-Acl -Path "Registry::$registryPath" -AclObject $acl
Write-Host "Inheritance disabled and FullControl denied for $user on $registryPath"