Solved

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

Posted on 2014-12-09
6
297 Views
Last Modified: 2014-12-09
Hi,
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:
FullName
R:\Groups\Accounting\Grants1
R:\Groups\Accounting\Grants2

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?
0
Comment
Question by:rloganrlogan
  • 3
  • 2
6 Comments
 
LVL 84

Assisted Solution

by:oBdA
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

0
 
LVL 40

Accepted Solution

by:
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

0
 
LVL 84

Expert Comment

by:oBdA
ID: 40489709
D'oh. And I was desperately searching in the .Access properties ...
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:rloganrlogan
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

TIA.
0
 
LVL 84

Expert Comment

by:oBdA
ID: 40489779
Nope.
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

0
 

Author Comment

by:rloganrlogan
ID: 40489803
Awesome!  Thank you so much!
0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help Creating PowerShell Script 4 46
Permission on folders 6 24
BatchFile-Disk Detection 23 31
Ruby or Python 7 61
Utilizing an array to gracefully append to a list of EmailAddresses
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

726 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