1
votes

I'm new to Powershell and I need to know how to list all permissions of a folder for a specific user. This is what I have discovered so far:

$ReferenceAccountName = 'DOMAIN\Username' 
[string[]]$SearchDirectories
= @('X:\SomeDirectory', 'F:\AnotherDirectory')

foreach ($RootDir in $SearchDirectories) {
    $DirACL = Get-Acl -Path $RootDir
    foreach ($ACL in $DirACL.Access){
        if ($ACL.IdentityReference -like $ReferenceAccountName){
            Write-Output $RootDir
        }
    }
    foreach ($Directory in (Get-ChildItem -Path $RootDir -Recurse | `
                            Where-Object -FilterScript {$_.Attributes `
                            -contains 'Directory'})){
        $DirACL = Get-Acl -Path $Directory.FullName
        foreach ($ACL in $DirACL.Access){
            if ($ACL.IdentityReference -like $ReferenceAccountName){
                Write-Output $Directory.FullName
            }
        }
    } }

However, this does not return any value with the Write-Output command. Changing it to Write-Host didn't work as well. Am I missing some crucial parts?

I'm using Powershell V2.0

1
Is it only one folder? So that you have one specific path to it? If yes, is this a shared folder or locally stored?verfluecht
There is no difference. Tried it with a shared folder and with a local folderAndr0mega
take a look at my answer, should do it for youverfluecht

1 Answers

0
votes

If I understood your question correctly, this should make it:

$user = "domain\username"
$path = "C:\Users\daisies"
$list = Get-ChildItem $path -Recurse | Where-Object {(Get-Acl $_.FullName).Access | Where-Object {$_.IdentityReference -eq $user} }
Write-Output $list

This outputs a list with your permission, LastWriteTime and filename.