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

PowerShell: Discover Domain Controllers and Classify Each As VM or Physical

Current Version $dcObjects=Get-ADDomainController -Filter * | select Name,OperationMasterRolesforeach ($dc in $dcObjects){ $dcName=$dc.Name $dcRole=$dc.OperationMasterRoles try{ $machineModel=(Get-WmiObject…

PowerShell: Get Available RAM Slots

# getRamSlotsAvailable.ps1 $computername=$env:computername function getRamSlotsAvailable{ param($computername=$env:computername) write-host "Computer name: $computerName" $slots = Get-WmiObject -Class "win32_PhysicalMemoryArray"…

User Account Control

Via Domain Policy: Create new GPO >> Edit >> Computer Configuration >> Policies >> Windows…