0

I am trying to export formatted folder ACL permission list for a limited set of folders on a file server. I have a list of folders to read out permissions from and a list of file names that I want to output the ACL permissions to.

   Folder Name   to  report file
1) E:\share\Legal  > D:\reports\legal.txt
2) E:\share\Ops > D:\reports\ops.txt
3) E:\share\Exec > D:\reports\exec.txt

I have to do 150 of these.
I have the powershell command that will put out exactly what I need:

(get-acl "E:\share\Legal").access | ft IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -auto > e:\report\legal.txt

I know I need to define the variable (i.e. $path) and maybe another variable (i.e. $output) but how do I relate one list to the other so that the correct $path variable is aligned with the related $output variable? I have so many limitations in this area that googling leads me in far over my head.

UPDATE: Haven't solved my stated issue yet but I have greatly improved my script and the resulting data file. Figured out that my csv output was failing because I was using "ft" instead of "select" for the data grid. I also eliminated an unneeded line from the CSV output with the "-notypeinformation" (or "-nti" for short)

(get-acl "E:\share\Legal").access | Select IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags | Export-csv e:\report\legal.csv -nti

UPDATE2: LotPing's answer including my after-answer changes to the original script:

## Q:\Test\2018\06\23\sf_917865.ps1
$BaseDir = 'E:\share\'
$BaseRep = 'D:\reports\'
$Folders = @('Legal','Ops','Exec')

$Rights  = @('IdentityReference',
             'FileSystemRights',
             'AccessControlType',
             'IsInherited',
             'InheritanceFlags')

ForEach ($Folder in $Folders){
    (Get-Acl "$BaseDir$Folder").Access | 
        Select $Rights | Export-CSV "$BaseRep$Folder.csv" -nti
}

For anyone faced with the same task, the last part of my task was to import all of these output files to an excel workbook as separate worksheets which I did in Excel using the VBA script found here, https://www.extendoffice.com/documents/excel/3230-excel-import-multiple-csv-files.html#a1

Magellan
  • 4,451
  • 3
  • 30
  • 53
sys-idjit
  • 3
  • 3
  • 2
    Possible duplicate of [List user's folder access permissions](https://serverfault.com/questions/171320/list-users-folder-access-permissions) – LotPings Jun 23 '18 at 09:24
  • Easiest option for a novice: two parallel arrays, and step through with a for loop with a counter. `$path = "a","b"; $output = "y","z"; for ($i = 0; $i -lt $path.Length; $i++) { (get-acl $path[$i]).access | ft IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -auto > $output[$i] }` Path a outputs to y, and b to z, in the example. – Matthew Wetmore Jun 23 '18 at 14:40
  • LotPIngs, thanks, the first answer in that article looks close to what I am trying to do. Again my knowledge falls short but will the output section of that section ( "foreach ($ACL in $DirACL.Access){ if ($ACL.IdentityReference -like $ReferenceAccountName){ Write-Output $Directory.FullName) ) create separate output files for each entry in "$SearchDirectories"? – sys-idjit Jun 23 '18 at 19:42
  • Mathew Wetmore - Thanks! That looks like a workable answer. Couple questions, is the "[$i]" the same as "$item"? Also, is the order of "$path" and "$output" just determined by the order of each item in the respective list? (i.e. the third item in the "$path" is matched to the third item in "$output", regardless of any other factor? – sys-idjit Jun 23 '18 at 19:54

1 Answers1

2

Take a modular approach with variables, arrays and a ForEach loop.

## Q:\Test\2018\06\23\sf_917865.ps1

$BaseDir = 'E:\share\'
$BaseRep = 'D:\reports\'
$Folders = @('Legal','Ops','Exec')

$Rights  = @('IdentityReference',
             'FileSystemRights',
             'AccessControlType',
             'IsInherited',
             'InheritanceFlags')

ForEach ($Folder in $Folders){
    (Get-Acl "$BaseDir$Folder").Access | 
        Format-Table $Rights -auto > "$BaseRep$Folder.txt"
}
LotPings
  • 1,015
  • 7
  • 12
  • 1
    It's sooo beautiful! – sys-idjit Jun 23 '18 at 19:59
  • 1
    Worked like a champ. Final version I used included in my question as UPDATE2. Thanks LotPings! Saved me many hours of work and made this task so easy I can delegate it! Saving me even more time! – sys-idjit Jun 23 '18 at 20:17