Check Whether an Entity Has Access to a Directory or Its Children

Write-Host "This script just be ran in the context of a File Server Administrators member"
Write-Host "It only checks whether an account has explicit permissions to access to a directory and it's contents"

Do{
#$path=Read-Host -Prompt 'Enter a UNC path';
#$entity=Read-Host -Prompt 'Username or Groupname'
$path="\\FILESERVER01\SHARE01"
$entity="Everyone"
$directories=@{path=$path};
$exclusion

"Running as: "+(whoami)

    try{
        # Change into the filesystem's current location
        Push-Location (Get-Location -PSProvider FileSystem)
        @( $directories ) | ForEach-Object {
            $items=Get-ChildItem $_.path -recurse
            
            foreach ($item in $items){
                #$result+=,($item,(($item | get-acl).Access | ?{$_.IdentityReference -match $entity}).FileSystemRights)
                #Split-Path $item.pspath -Resolve -Leaf
                Convert-Path $item.pspath
                #Remove-NTFSAccess -Path (Convert-Path $item.pspath) -Account $entity -AccessRights FullControl -AccessType Allow
                #Remove-NTFSAccess -Path (Convert-Path $item.pspath) -Account $entity -AccessRights FullControl -AccessType Deny 
                }
            }
        }
    finally {
       # Revert to the previous location
       Pop-Location
       #$result
        }

$flag = Read-Host -Prompt 'Press Any Key = exit; R = Repeat...'} while ($flag -match '[Rr]')

Leave a Reply

Your email address will not be published. Required fields are marked *