locked
Generate folder list to text file then get ACL of the listed folders in the text file RRS feed

  • Question

  • Hi,

    I'm fairly new with Posh and I was trying to lessen the load on the server by first getting a list of folders from a specific location and out put it to a text file. And from there get the listed folders ACL. So far I wa able to generate the text file showing the directory of the folder, but when I tried to get the ACL of the said directory, I get an error path not found. I hope you could help me out. 

    Remove-Item "D:\Users\finaloutput.csv" -ErrorAction SilentlyContinue
    #this contains the sharefolder location
    $path = Get-Content -path D:\Users\firststpath.txt
    $FolderPath = $path | Get-ChildItem -Directory -Force -Recurse -ErrorAction SilentlyContinue
    $Folderpath | Out-File -FilePath D:\Users\secondpath.txt -Force -ErrorAction SilentlyContinue
    $inputfile = "D:\Users\secondpath.txt"
    $FolderList = Get-Content $InputFile
    $Output = @()
    ForEach ($Folder in $Folderlist) {
        $Acl = Get-Acl -Path $Folder.FullName
        ForEach ($Access in $Acl.Access) {
    $Properties = [ordered]@{'Folder Name'=$PSPath.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
    $Output += New-Object -TypeName PSObject -Property $Properties            
    }
    }
    $Output | Export-Csv D:\Users\finaloutput.csv

    Monday, September 16, 2019 9:07 AM

All replies

  • Start by using help to learn how each CmdLet works,

    help Import-Csv -online

    Do this for all CmdLets so you can understand what they do and how to use them.

    You cannot learn PowerShell by guessing.  You must learn the commands and syntax before trying to write code.

    The syntax you are suing requires a CSV but you only have a text file.


    \_(ツ)_/

    Monday, September 16, 2019 9:17 AM
  • Hi,

    Thanks for the advise, originally the output file (secondpath) was in csv format, but it bloated to 100MB, so I thought changing it to a text file would make it smaller, but for the ACL part it was not able to read the path listed in the text file, since the list (text file) contains other information aside from the list of paths. Here is a sample of the text output


        Directory: D:\Program Files



    Name           : 7-Zip
    CreationTime   : 6/14/2016 1:27:00 PM
    LastWriteTime  : 6/14/2016 1:27:00 PM
    LastAccessTime : 6/14/2016 1:27:00 PM

    Name           : Mozilla_Firefox
    CreationTime   : 1/27/2017 3:45:46 PM
    LastWriteTime  : 1/16/2019 9:35:17 AM
    LastAccessTime : 1/16/2019 9:35:17 AM

    Name           : RES Software
    CreationTime   : 6/10/2016 12:15:15 PM
    LastWriteTime  : 6/10/2016 12:15:15 PM
    LastAccessTime : 6/10/2016 12:15:15 PM



        Directory: D:\Program Files\7-Zip



    Name           : Lang
    CreationTime   : 6/14/2016 1:27:00 PM
    LastWriteTime  : 6/14/2016 1:27:00 PM
    LastAccessTime : 6/14/2016 1:27:00 PM

    So this is where I'm stuck. Is there a way to just capture the Directory from this list so I can run the Get-ACL command for all folders and subfolders listed.

    Sorry if this might sound dumb, but as I mentioned, I'm just started scripting. I read the help files but, its not giving me a hint of what should I do.

    If not, I'll go back to the original script below, which takes too long to run and finish.

    Remove-Item -Path D:\Users\groupfoldertest.csv -Force -ErrorAction SilentlyContinue
    $path = Get-Content -Path D:\Users\groupfolder.txt -Force
    $FolderPath = $path | Get-ChildItem -Directory -Force -Recurse -ErrorAction SilentlyContinue
    $Output = @()
    ForEach ($Folder in $FolderPath) {
        $Acl = Get-Acl -Path $Folder.FullName
        ForEach ($Access in $Acl.Access) {
    $Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
    $Output += New-Object -TypeName PSObject -Property $Properties            
    }
    }
    $Output | Export-Csv -Delimiter ";" -Force -NoTypeInformation -Path D:\Users\groupfoldertest.csv

    Br.


    • Edited by Richard0405 Monday, September 16, 2019 12:11 PM
    Monday, September 16, 2019 12:05 PM