Version

RegistrySecurity 0.3.zip - 0.3 (Beta)
 

Introduction

Managing permissions with PowerShell is only a bit easier than in VBS or the command line as there are no cmdlets for most day-to-day tasks like getting a permission report or adding permission to an item. PowerShell only offers Get-Acl and Set-Acl but everything in between getting and setting the ACL is missing. This module closes the gap.

Documentation

Each cmdlet is documented. The help can be retreived like for any other cmdlet using Get-Help. Don't forget to use the example switch. To see the help for each single parameter use the full switch parameter of the Get-Help cmdlet.


Comments, feature requests and bug reports are very welcome: raandree@live.com

Installation

Just create the folder "RegistrySecurity" in one of the standard module folders and copy the files attached in there. The standard module folders are in the environment variable %PSModulePath%, for example C:\Users\<username>\Documents\WindowsPowerShell\Modules.

For example, all the files in the zip file have to be in "C:\Users\raandree\Documents\WindowsPowerShell\Modules\RegistrySecurity". If you did this then the module should be listed in "Get-Module -ListAvailable" and can be imported using "Import-Module RegistrySecurity".


Description

The module provides 10 cmdlets to manage permissions inside the registry, like adding and removing ACEs, setting the inheritance, getting the current permissions or even get the effective permissions for a certain user.
The available cmdlets are listed below with a short description. More information can be retreived in the PowerShell using Get-Help.
All cmdlets have at least one parameter that supports the pipeline. They all can work with pipeline input coming from Get-ChildItem but some do more with what comes form the pipeline. For excample you can remove permission by piping what Get-Ace returns to Remove-Ace:
PowerShell
Edit|Remove
dir | Get-Ace -ExcludeInherited | Remove-Ace
The pipeline support can also be used to backup and restore permissions of one or many items:
PowerShell
Edit|Remove
#to backup permissions just pipe what Get-Ace returns to Export-Csv 
dir | Get-Ace -ExcludeInherited | Export-Csv permissions.csv 
 
#to retore the permissions pipe the imported data to Add-Ace 
#As the imported data also contains the path you do not need to specify the item 
Restore: Import-Csv .\permissions.csv | Add-Ace 
All cmdlets can handle SIDs and also SamAccountNames. The output contains always both unless a SID is not resolvable.
The types.ps1xml file is extending the common objects with some useful information and the format.ps1xml file formats all the output in almost the same way like the Get-ChildItem output.
By implementing the [Process Privilege http://processprivileges.codeplex.com/] project the cmdlets can activate the required privileges for setting the ownership for example.


Add-Ace

Adds a specific ACE to the current object. This can be done in just one line:
PowerShell
Edit|Remove
Get-Item .\Test | Add-Ace -Account Contoso\JohnD -AccessRights FullControl

Enable-Inheritance

It can be a problem if certain files or folders on a volume have inheritance disabled. Making sure that inheritance is enabled can be done using this cmdlets:
PowerShell
Edit|Remove
Get-Item .\Test -Recurse | Enable-Inheritance

Disable-Inheritance

See Enable-Inheritance

Get-Ace

Gives you a list of all permissions . normally you are interested not in the inherited permissions so the switch ExcludeInherited can be useful
PowerShell
Edit|Remove
Get-Item HKCU:\test | Get-Ace –ExcludeInherited
 Filtering works with Where-Object
PowerShell
Edit|Remove
Get-Item HKCU:\test | Get-Ace | Where-Object { $_.ID -like "*users*" }

Get-EffectivePermissions

Shows the permissions an account actually has on a file or folder. If no parameter is specified it shows the effective permissions for the current user. However you can supply a user by using the SID or account name
PowerShell
Edit|Remove
Get-Item F:\backup | Get-EffectivePermissions -Account S-1-5-32-545

Get-Inheritance

Shows if inheritance is blocked

Get-OrphanedAce

Lists all permissions that can no longer be resolved. This normally happens if the account is no longer available so the permissions show up as a SID and not as an account name.

To remove all non-resolvable or orphaned permissions you can use the following line. But be very careful with that as maybe the account is not resolvable due to a network problem.
PowerShell
Edit|Remove
dir -Recurse | Get-OrphanedAce | Remove-Ace

Get-Owner

Shows the owner of a file or folder
PowerShell
Edit|Remove
dir -Recurse | Get-Owner
 

Remove-Ace

Removes the permission for a certain account. As the pipeline is supported it takes also ACEs coming from Get-Ace or Get-Get-OrphanedAce

Set-Owner

Sets the owner to a specific account like:
PowerShell
Edit|Remove
Set-Item .\Data | Set-Owner -Account builtin\administrators