Posted On March 29, 2019

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

kimconnect 0 comments
blog.KimConnect.com >> Codes , Windows >> 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 *

Related Post

Setting Windows Security Auditing via Command Line

Please be advised that the follow auditpol cmdlet would be overridden by Group Policies in…

PowerShell: Nesting Functions Inside Functions

Demo 1: calling a function from within another function function A{ Param($functionToCall) Write-Host "Calling function:…

SQL AlwayOn High Availability Default Port

Internal SQL DEV & QA environments may have SQL listening to the default port of…