Powershell get child item list path to long and could not read error exception RRS feed

  • Question

  • I have been taking different approaches at this but the try and catch is not panning out.  This find at seems to show like it is on the track of what i am after.

    I have modified the code slightly in hopes of capturing folders with the error Could not find item S:\studentPics\xxxxx

    the issue is if i don't have read access i can get directory and i need to report that along with folders that are to long.

    Thanks so much in advance 

    Approach 1 ( i have tried many variations of this all failed)

    $folder = "S:\studentPics"
    try {(Get-ChildItem -Attributes Directory "$folder\*" -ErrorAction Continue).FullName } catch {"opps folder $_"}

    Approach 2 ( i have tried many variations of this all failed)

    Get-ChildItem -Attributes directory -Path $folder\* -Recurse -ErrorAction SilentlyContinue -ErrorVariable err
    foreach ($errorRecord in $err)
        if ($errorRecord.Exception -is [System.IO.\])
            Write-Warning "Cannot read dir '$($errorRecord.TargetObject)'."
            Write-Error -ErrorRecord $errorRecord


    Monday, June 22, 2015 2:01 PM


  • i found my solution

    Thanks to

    Get-Access  -Account "SCHOOLS\ShareAdmins" |select Name,FullName,InheritanceEnabled,InheritedFrom,AccessRights,Account,IsInherited,PropagationFlags  | Export-Csv c:\temp\PReport.csv -NoTypeInformation
    Get-ChildItem  "s:\" -Recurse -ErrorAction SilentlyContinue -ErrorVariable gci_errors | ForEach-Object {
        $_ |  Get-Access -Account "SCHOOLS\ShareAdmins" -ErrorAction SilentlyContinue -ErrorVariable gacl_errors |select Name,FullName,InheritanceEnabled,InheritedFrom,AccessRights,Account,IsInherited,PropagationFlags  | Export-Csv c:\temp\PReport.csv -Append
    $gci_errors | Select-Object -ExpandProperty CategoryInfo | Export-Csv -NoTypeInformation -Path C:\Temp\gci_errors.csv 
    $gacl_errors | Select-Object -ExpandProperty CategoryInfo | Export-Csv -NoTypeInformation -Path C:\Temp\gacl_errors.csv


    • Marked as answer by Lishron Monday, June 22, 2015 2:57 PM
    Monday, June 22, 2015 2:57 PM