Search code examples
powershellrights

How can test real access right for other User-Account in powershell


I need to try if a specific user has read or write acces on DFS Folder (to validate my DFS).

I am Admin on the domain and I have the credential of this user in $Credentials but Test-Path, Get-Item, New-Item do not accept the credential


Solution

  • instead check acl recursively, i use real write access with Start-Process and specific credential (start-process is an alias of runas). the process write a new file with $(whoami) content after ending process check if file exist and his content.

    function test-Write ($folder)
        $WinCredential = Get-Credential -UserName "Domain\User" -Message "Login"
        Start-Process -WindowStyle Hidden -Wait -Credential $WinCredential -FilePath "powershell.exe" -ArgumentList "whoami | out-file '$folder\test.txt'"
        if ((get-content "$folder\test.txt") -like "Domain\User") {
           return 'OK'
        }
        return 'Erreur NTFS Access'
    }