?
Solved

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

Posted on 2014-12-09
6
Medium Priority
?
355 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:Robert Logan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 85

Assisted Solution

by:oBdA
oBdA earned 1000 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 41

Accepted Solution

by:
footech earned 1000 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 85

Expert Comment

by:oBdA
ID: 40489709
D'oh. And I was desperately searching in the .Access properties ...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Robert Logan
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 85

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:Robert Logan
ID: 40489803
Awesome!  Thank you so much!
0

Featured Post

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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 …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

649 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