我是Powershell的新手,我需要知道如何列出特定用户的文件夹的所有权限。这是我到目前为止发现的:
$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
}
}
} }
但是,使用Write-Output命令不会返回任何值。将其更改为Write-Host不能正常工作。我是否缺少一些关键部分?
我正在使用Powershell V2.0
答案 0 :(得分:0)
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.