ACL Permissions powershell script erroring out and not providing results in created files

Here is our script:
Function Get-ACE {            
Param (            
        [parameter(Mandatory=$true)]            
        [string]            
        [ValidateScript({Test-Path -Path $_})]            
        $Path            
)            
           
    $ErrorLog = @()            
           
    Write-Progress -Activity "Collecting folders" -Status $Path `
        -PercentComplete 0            
    $folders = @()            
    $folders += Get-Item $Path | Select-Object -ExpandProperty FullName            
 $subfolders = Get-Childitem $Path -Recurse -ErrorVariable +ErrorLog `
        -ErrorAction SilentlyContinue |            
        Where-Object {$_.PSIsContainer -eq $true} |            
        Select-Object -ExpandProperty FullName            
    Write-Progress -Activity "Collecting folders" -Status $Path `
        -PercentComplete 100            
           
    # We don't want to add a null object to the list if there are no subfolders            
    If ($subfolders) {$folders += $subfolders}            
    $i = 0            
    $FolderCount = $folders.count            
           
    ForEach ($folder in $folders) {            
           
        Write-Progress -Activity "Scanning folders" -CurrentOperation $folder `
            -Status $Path -PercentComplete ($i/$FolderCount*100)            
        $i++            
           
        # Get-ACL cannot report some errors out to the ErrorVariable.            
        # Therefore we have to capture this error using other means.            
        Try {            
            $acl = Get-ACL -LiteralPath $folder -ErrorAction Continue            
        }            
        Catch {            
            $ErrorLog += New-Object PSObject `
                -Property @{CategoryInfo=$_.CategoryInfo;TargetObject=$folder}            
        }            
           
        $acl.access |            
            Where-Object {$_.IsInherited -eq $false} |            
            Select-Object `
                @{name='Root';expression={$path}}, `
                @{name='Path';expression={$folder}}, `
                IdentityReference, FileSystemRights, IsInherited, `
                InheritanceFlags, PropagationFlags            
           
    }            
               
    $ErrorLog |            
        Select-Object CategoryInfo, TargetObject |            
        Export-Csv ".\Errors_$($Path.Replace('\','_').Replace(':','_')).csv" `
            -NoTypeInformation            
           
}            
           
# Call the function for each path in the text file            
Get-Content .\paths.txt |            
    ForEach-Object {            
        If (Test-Path -Path $_) {            
            Get-ACE -Path $_ |            
                Export-CSV `
                    -Path ".\ACEs_$($_.Replace('\','_').Replace(':','_')).csv" `
                    -NoTypeInformation            
        } Else {            
            Write-Warning "Invalid path: $_"            
        }            
    }  

Here is an example of our error code.
Export-CSV : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the
directory name must be less than 248 characters.
At C:\Users\c51136a\Desktop\Power shell Stuff\Test1.ps1:65 char:17
+                 Export-CSV `
+                 ~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Export-Csv], PathTooLongException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand
 
Export-CSV : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the
directory name must be less than 248 characters.
At C:\Users\c51136a\Desktop\Power shell Stuff\Test1.ps1:65 char:17
+                 Export-CSV `
+                 ~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Export-Csv], PathTooLongException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand
Member_2_6244776Systems EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
I think the error is pretty clear.  The path (including the filename) that you're providing for the .CSV file for the Export-CSV cmdlet is too long.  Since you're writing the files in the current directory, it may be enough for you to run the script from a shorter path (like C:\temp), or you could code in the output directory specifically.  Try this for the last bit.
# Call the function for each path in the text file            
foreach ( $line in (Get-Content .\paths.txt) )
{
    If (Test-Path -Path $line) {            
        Get-ACE -Path $line |            
            Export-CSV `
                    -Path "c:\temp\ACEs_$($line.Replace('\','_').Replace(':','_')).csv" `
                    -NoTypeInformation            
    } Else {            
        Write-Warning "Invalid path: $line"            
    }            
}

Open in new window


*Edit to avoid variable name reuse.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PberSolutions ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: footech (https:#a42384804)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Pber
Experts-Exchange Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.