?
Solved

get-acl and split output from accessToString

Posted on 2011-05-11
3
Medium Priority
?
3,090 Views
Last Modified: 2012-05-11
I am attempting to return the accessToString on multiple files in order to output the data and determine current access... this is getting me what I want with one exception... only "one entry" is returned per file, where I know there are multiple... need to figure out how to split the output for accesstostring
foreach($obj in $queryList){
$a = get-acl $obj | select fullname,pschildname,accesstostring
$acls = @()
$a |% {
$b = ""|select name,security_principal,type,rights
$b.name = $obj
$_.accesstostring |%{
$_ -match "(.+)\s((?:Allow)|(?:Deny))\s(.+)"
$b.security_principal = $matches[1]
$b.type = $matches[2]
$b.rights = $matches[3]
$acls += $b
}
}
$acls
}

Open in new window

0
Comment
Question by:daveTechSearch
3 Comments
 
LVL 13

Assisted Solution

by:soostibi
soostibi earned 1000 total points
ID: 35744146
There is no sense in working with the AccessToString, if you want to use the portions of that. It's much simpler to use the raw objest instead:
foreach($obj in $queryList){  
    get-acl $obj | %{$_.access} | ForEach-Object {
        $_ | Select-Object @{n="name";e={$obj.fullname}}, 
            @{n="security_principal";e={$_.identityreference}},
            @{n="type";e={$_.accesscontroltype}},
            @{n="rights";e={$_.filesystemrights}}
    }
}

Open in new window

0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 1000 total points
ID: 35744414
I would do...
foreach($obj in $queryList){  
  Get-Acl $obj | Select-Object -ExpandProperty Access | Select-Object @{n="name";e={ $obj.fullname }}, 
    @{n="security_principal";e={ $_.identityreference }},
    @{n="type";e={ $_.accesscontroltype }},
    @{n="rights";e={ $_.filesystemrights }}
}

Open in new window

The other has too many loops for me :)

Chris
0
 
LVL 5

Author Closing Comment

by:daveTechSearch
ID: 35747614
Perfect!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Loops Section Overview
Screencast - Getting to Know the Pipeline

809 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