Reputation: 357
I'm given the user domain\name, password and the path and I want to show if given user has write or/and read access in given directory.
General idea:
function Has-Read-Access {
param(
[Parameter(Mandatory=$true)][string]$userLogin
[Parameter(Mandatory=$true)][string]$userPwd
[Parameter(Mandatory=$true)][string]$directory
)
$hasReadAccess = 0
#insert magic here
return $hasReadAccess
}
Has-Read-Access -userLogin 'DOMAIN\user' -userPwd 'Passw0rd' -directory 'C:\FolderName\'
I have tried running the powershell.exe
by a different user:
Start-Process powershell.exe -Credential "TestDomain\Me"
But it seems like a wrong approach.
Upvotes: 2
Views: 7938
Reputation: 13453
The easy way to see who has Effective access to a folder use (PowerShellAccessControl Module 3.0/4.0
And some code like:
Get-Item $directory | Get-EffectiveAccess -Principal $UserName
To get the list of users who have access to a folder use Get-ACL (TechNet Article)
Get-ACL $Directory
Note: you don't need to know someone's password to get what access they have.
Upvotes: 6