0

I am not a powershell expert, but I have written some smaller scripts. Now working on a script which returns me the ACL of a folder and it children.

When I simply run get-acl I receive a lot of info, which I would like to filter our or skip. Basically I need:

  • Full path, without Microsoft.Powershell.Core stuff..
  • Group
  • Access (don't need NT-Authori... users/groups)

So far I tried something like that:

get-childitem -recurse "$myfolder" | get-acl | select -PSPATH, Group, Access

but in this way I don't get the full names displayed.

4 Answers 4

0

you can do something like this:

$acl = Get-Acl -Path $path
$group = acl.Access | ForEach-Object {$_.identityReference.value} 
$Access = acl.Access | ForEach-Object {$_.FileSystemRights}
3
  • yes that'S more or less what I did. Do you remember the command to display the full string of output? not just the first xx characters? also I shows still the microsoft.powershell stuff in the path. Dec 18, 2015 at 14:04
  • which full string of Output and where did you get just the first few characters?
    – N.R.
    Dec 18, 2015 at 15:06
  • for the path for example. Dec 18, 2015 at 15:08
0

If you use Format-Table to output the data, you can use the -AutoSize property to force it to display all the information.

Regarding the full path you could either use:

get-childitem -recurse "$myfolder" | select FullName

or the messier option IMO:

$FullPath = $acl.path -replace ".*::"

The second option uses string manipulation to remove all text upto and including the "::"

Edit :-

This is the complete code I've used:

$Output = @()
$Path = "C:\SomePath"

$ChildItems = Get-ChildItem -Recurse -Path $Path
foreach($ChildItem in $ChildItems)
{
    $FullPath = $ChildItem.FullName
    $acl = get-acl $FullPath
    $Access = $acl.Access

    foreach ($AccessObject in $Access)
    {
       $Group = $AccessObject.IdentityReference.value
       $Rights = $AccessObject.FileSystemRights

       $Line = New-Object PSObject
       $Line | Add-Member -membertype NoteProperty -name "Path" -Value $FullPath
       $Line | Add-Member -membertype NoteProperty -name "Group" -Value $Group
       $Line | Add-Member -membertype NoteProperty -name "Rights" -Value $Rights
       $Output += $Line
    }
}
$Output | Format-Table -AutoSize 
0

Try this code. This is what I m using. Supply the list of folders in Path.txt file, which you need the ACLs for.

$erroractionpreference = "Continue"

$todaytime = Get-Date -format ddMMMyy_HH-mm

$OutPath = ".\ACL_" + $todayTime + ".txt"

$ACLS=get-content .\Path.txt

$Out=foreach ($ACL in $ACLS) 
{ 
    write-host $ACL -foregroundcolor green
    get-acl $ACL  | select @{Label="Path";Expression={echo $ACL}},@{Label="Access";Expression={$_.AccesstoString}} | ft -wrap -a 
}  

  echo $out >> $OutPath
0

My preference (includes removing Microsoft.PowerShell.Core\FileSystem:: ):

Get-ChildItem . -recurse | get-acl | Select-Object -Property @{Name='Path';Expression={Convert-Path $_.Path}},Group,AccessToString

Tough I recommend using Format-List or Out-Gridview:

Get-ChildItem . -recurse | get-acl | Select-Object -Property @{Name='Path';Expression={Convert-Path $_.Path}},Group,AccessToString | fl
Get-ChildItem . -recurse | get-acl | Select-Object -Property @{Name='Path';Expression={Convert-Path $_.Path}},Group,AccessToString | Out-GridView

I am searching for excluding or only show matching lines in the AccessToString property too, but have not yet found what I need. Curiosity: What do you need "Group" for? "Owner" might make fore sense, from my point of view, so if you have a usage for "Group" I am curious to know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.