Solved

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

Posted on 2014-12-09
6
254 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 82

Assisted Solution

by:oBdA
oBdA earned 250 total points
Comment Utility
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 39

Accepted Solution

by:
footech earned 250 total points
Comment Utility
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 82

Expert Comment

by:oBdA
Comment Utility
D'oh. And I was desperately searching in the .Access properties ...
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:rloganrlogan
Comment Utility
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 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
Awesome!  Thank you so much!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now