How can I get access permissions for folders (recursive) and display the full path

Posted on 2014-12-09
Last Modified: 2014-12-09
I'm trying to write a PowerShell script that will output ACLs for folders (recursively) with the full path.

So far, I have two working scripts -- the first will output all folders in a directory recursively (with the full path) but with NO ACLs.  The second will output ACLs for folders recursively but will NOT display the full path.  Both scripts only apply to the working directory, i.e. R:\Groups\Accounting.  After a change to the R:\Groups\Accounting folder in PowerShell, I run these two single commands.

So, the first script (which will display the full path) is --
get-childitem -directory  -recurse | select-object FullName |  Out-Gridview

Sample output of first script:

The second script is --
get-childitem -directory  -recurse | select-object FullName |  foreach-object {Get-Acl $_.Fullname} | Out-Gridview

Sample output of second script:
Path          Owner          Access
Grants1      john.doe      UM\john.doe Allow FullControl      
                                          BUILTIN\Administrators Allow FullControl
Grants2     jane.doe       UM\jane.doe Allow FullControl
                                          BUILTIN\Administrators Allow FullControl  

What I'd like to see is --
Path                                                     Owner           Access                                        
R:\Groups\Accounting\Grants1      john.doe      UM\john.doe Allow FullControl      
                                                                                   BUILTIN\Administrators Allow FullControl

R:\Groups\Accounting\Grants2     jane.doe       UM\jane.doe Allow FullControl
                                                                                  BUILTIN\Administrators Allow FullControl

Any chance of achieving this with a sample line of PS code?
Question by:rloganrlogan
  • 3
  • 2
LVL 83

Assisted Solution

oBdA earned 250 total points
ID: 40489460
Get-ChildItem -Directory -Recurse | % {Get-Acl $_.Fullname} | Select @{n="Path";e={$_.PSPath.Split(":", 3)[2]}}, Owner, @{n="Access";e={($_.Access | % {"$($_.IdentityReference) $($_.AccessControlType) $($_.FileSystemRights)"}) -join "`r`n"}} | Out-Gridview

Open in new window

LVL 39

Accepted Solution

footech earned 250 total points
ID: 40489686
No need to give points for this, but just wanted to point out a code simplification (it does the same as oBdA's).
Get-ChildItem -Directory -Recurse | Get-Acl | Select @{n="Path";e={($_.Path -Split "::")[-1]}},Owner, @{n="Access";e={$_.AccessToString}} | Out-Gridview

Open in new window

LVL 83

Expert Comment

ID: 40489709
D'oh. And I was desperately searching in the .Access properties ...
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.


Author Comment

ID: 40489765
If I wanted to prompt for the path using --
$Path = Read-Host -Prompt 'Enter path'

...would the next line be --

Get-ChildItem -Directory -Recurse | Get-Acl | Select @{n=$Path;e={($_.Path -Split "::")[-1]}},Owner, @{n="Access";e={$_.AccessToString}} | Out-Gridview

LVL 83

Expert Comment

ID: 40489779
Get-ChildItem -Path $Path -Directory -Recurse | Get-Acl | Select @{n="Path";e={($_.Path -Split "::")[-1]}}, Owner, @{n="Access";e={$_.AccessToString}} | Out-Gridview

Open in new window


Author Comment

ID: 40489803
Awesome!  Thank you so much!

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question