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

Basic CSS: Import a Google Font

<style>.red-text {color: red;}p {font-size: 16px;font-family: monospace;}</style><h2 class="red-text">CatPhotoApp</h2><main><p class="red-text">Click here to view more <a href="#">cat photos</a>.</p><a…

PowerShell Script to Send Email

Use this newer method: https://blog.kimconnect.com/powershell-script-to-send-emails/ ### Variables section ###$fromaddress = "[email protected]"$toaddress = "[email protected]"$bccaddress = ""$CCaddress…

PowerShell: List All Hyper-V Snapshots of All VMs in All Clusters in Domain

# listHyperVSnapshots.ps1 $clusterName='*' function listAllHyperVSnapshots([string[]]$clusterName){ function includeRSAT{ $ErrorActionPreference='stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 #$rsatWindows7x32='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x86-RefreshPkg.msu' $rsatWindows7x64='https://download.microsoft.com/download/4/F/7/4F71806A-1C56-4EF2-9B4F-9870C4CFD2EE/Windows6.1-KB958830-x64-RefreshPkg.msu' $rsatWindows81='https://download.microsoft.com/download/1/8/E/18EA4843-C596-4542-9236-DE46F780806E/Windows8.1-KB2693643-x64.msu' $rsat1709…