PowerShell Script to export folder permissions RRS feed

  • Question

  • Hi There,
    I'm having issues running the below script to export the folder permissions of all folder and sub folders on my file server. I have spent the last two days trying to work out why I can't get this working. When the script runs I get "Get-ChildItem : Could not find a part of the path". The file names do exist and the file paths are very long, but I'm unable to shorten them. Any suggestion as to what I am doing wrong?   

    This is a copy of the script I am using 

    $AllFolders = Get-ChildItem -Directory -Path "D:\deptkp"  -Recurse -Force
    $Results = @()
    Foreach ($Folder in $AllFolders) {
        $Acl = Get-Acl -Path $Folder.FullName
        foreach ($Access in $acl.Access) {
            if ($Access.IdentityReference -notlike "BUILTIN\Administrators" -and $Access.IdentityReference -notlike "domain\Domain Admins" -and $Access.IdentityReference -notlike "CREATOR OWNER" -and $access.IdentityReference -notlike "NT AUTHORITY\SYSTEM") {
                $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD Group'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
                $Results += New-Object -TypeName PSObject -Property $Properties
    $Results | Export-Csv -path "D:\Scripts\Permissions - $(Get-Date -format ddMMyy).csv"

    This is the full error i am seeing 

    Get-ChildItem : Could not find a part of the path 'D:\deptkp\etc...etc...'.
    At D:\Scripts\FileServerAuditAll.ps1:2 char:15
    + $AllFolders = Get-ChildItem -Directory -Path "D:\deptkp"  -Recurse -Force
    +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ReadError: (D:\deptkp\Colla...- SAMPLES - QA :String) [Get-ChildItem], DirectoryNotFound
        + FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand

    I am running this on a 2012r2 windows server

    Please let me know if more information is needed
    Thanks Nick

    Nicholas Refalo

    • Moved by Bill_Stewart Friday, January 26, 2018 2:42 PM This is not "fix/debug/rewrite my script for me" forum
    Sunday, November 26, 2017 11:35 PM

All replies

  • I recommend that you fix your servers file system before continuing.


    Monday, November 27, 2017 3:24 AM
  • Thank you jrv for your reply. Yes I agree and the purpose of this script. I need to work out how the file structure was built then I can work out how to fix it. So I just need to export the report so I can plan my next step. 

    Nicholas Refalo

    Monday, November 27, 2017 4:10 AM