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
$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.