powershell - 以递归方式列出域用户可以访问的所有目录
问题描述
递归列出所有目录很容易,如下所示:
Get-ChildItem G:\ -recurse -directory
编写一个列出特定目录权限的函数很容易:
get-acl $folder.access
如何递归检查每个目录的 ACL,然后输出仅包含域用户组可访问的列表?
解决方案
你可以这样做 :
Get-ChildItem G:\ -Directory -Recurse -ErrorAction SilentlyContinue |
Where { try { (Get-Acl -LiteralPath $_.FullName | Select -ExpandProperty Access |
Where { $_.IdentityReference -eq "MYDOMAIN\Domain Users" `
-and ($_.FileSystemRights -band [System.Security.AccessControl.FileSystemRights]::Read) -eq [System.Security.AccessControl.FileSystemRights]::Read `
-and $_.AccessControlType -eq [System.Security.AccessControl.AccessControlType]::Allow }) } catch { } }
里面的try
catch
块Where-Object
是为了避免错误,因为Get-Acl
当你无权访问路径时总是会抛出错误,即使你设置了-ErrorAction SilentlyContinue
的解释Where-Object
:
搜索“MYDOMAIN\域用户”:
$_.IdentityReference -eq "MYDOMAIN\Domain Users"
至少具有读取权限
($_.FileSystemRights -band [System.Security.AccessControl.FileSystemRights]::Read) -eq [System.Security.AccessControl.FileSystemRights]::Read
允许类型(可能被拒绝)
$_.AccessControlType -eq [System.Security.AccessControl.AccessControlType]::Allow
推荐阅读
- kubernetes - Kubectl - 如何从配置变量中读取入口主机?
- docker - 正如我所怀疑的那样,nginx 是否会输入“欢迎使用 Nginx!” 当它不知道还能做什么时?
- erlang - What is the regs() equivalent in Elixir?
- r - 填充多个 geom_area 的正确方法
- c++ - 解决链接器错误 MySQL 连接器/C++
- sql - 查找超过一分钟的记录
- python - 使用starflut在flutter中导入python模块
- c++ - 在不使用额外变量的情况下将不同的值输入到集合中(C++)
- python - Auto height paper Reportlab Python(关于打印购物收据的色带纸案例研究)
- c# - 在 ASP.NET Core 中仅使用输入按钮将参数传递给 Action 的发布表单