How to Manage Permissions to Registry Keys in Windows (PowerShell)
This sample demonstrates how to bulk get and set the access permission for registry keys using PowerShell.
If you want to get or set permission for one registry key, it’s easy for you to right click the registry key and click the Permission… option to view or set the permission. But if you need to check or set permissions for multiple registry keys, you may spend much time finishing it. The sample will help you to check or set permission for one or more registry keys using the PowerShell script.
This script contains the following advanced functions:
You can use this script in the following ways:
Method 1:
Method 2:
To obtain the detailed information about how to use the functions, run the following command to retrieve the help information:
Get-Help functionName -detailed
For example:
Get-Help Get-OSCRegistryKeyPermission -detailed
Notes:
To run script:
Here are some code snippets for your reference:
Code to get security permission of registry keys:
PowerShellEdit|RemovepowershellIf($registries) { $registries | ForEach-Object{ $regPath = TranslateRegistryKeyPath -Path $_ If($regPath) { If(Test-Path -Path $regPath) { Get-Acl -path $regPath | Format-List } Else { Write-Error ($regPath + " " + $Message.SpInvalidPath) } } } }If($registries) { $registries | ForEach-Object{ $regPath = TranslateRegistryKeyPath -Path $_ If($regPath) { If(Test-Path -Path $regPath) { Get-Acl -path $regPath | Format-List } Else { Write-Error ($regPath + " " + $Message.SpInvalidPath) } } } }
Code to set security permissions to registry keys:
PowerShellEdit|Removepowershell$aclRegistry= Get-Acl -Path $Path $aclRegistry.SetAccessRuleProtection($true, $true) $ruleRegistry = New-Object System.Security.AccessControl.RegistryAccessRule($Account,$RegistryRights,$InheritanceFlags,$PropagationFlags,$AccessControlType) Try { If($Type -eq "Add") { $aclRegistry.AddAccessRule($ruleRegistry) } Else { If($Type -eq "Remove") { $aclRegistry.RemoveAccessRule($ruleRegistry) | Out-Null } } } Catch { Throw $_.Exception.Message } Set-Acl -path $Path -AclObject $aclRegistry$aclRegistry= Get-Acl -Path $Path $aclRegistry.SetAccessRuleProtection($true, $true) $ruleRegistry = New-Object System.Security.AccessControl.RegistryAccessRule($Account,$RegistryRights,$InheritanceFlags,$PropagationFlags,$AccessControlType) Try { If($Type -eq "Add") { $aclRegistry.AddAccessRule($ruleRegistry) } Else { If($Type -eq "Remove") { $aclRegistry.RemoveAccessRule($ruleRegistry) | Out-Null } } } Catch { Throw $_.Exception.Message } Set-Acl -path $Path -AclObject $aclRegistry
Example 01: Get the security permissions of specific registry keys.
Command: Get-OSCRegistryKeyPermission –Path “RegistryKey01Path,RegistryKey02Path,…”
Screenshot:

Example 02: Set the specific security permissions to registry keys.
Command: Set-OSCRegistryKeyPermission -RegistryKeysPath <RegistryKeysPath > -Type <Type> -Account <AccountName > -RegistryRights <RegistryRightsName> [-InheritanceFlags <InheritanceFlagName>] [-PropagationFlags <PropagationFlagName>] -AccessControlType <AccessControlType>
Screenshot:
![]()
Windows PowerShell 2.0
Additional Resources
Technical Resource:
TechNet Library: Get-Acl