bash - 在网络驱动器组/用户名中获取 acl 而不是 SID
问题描述
我需要收集共享中每个文件夹的安全权限,结果返回给我 SID 但我需要用户名(或组名),我该怎么做?
$FolderPath = Get-ChildItem -Directory -Path "Y:\" -Recurse -Force
$Output = @()
ForEach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder.FullName
ForEach ($Access in $Acl.Access) {
$Properties = [ordered]@{'Folder Name'=$Folder.FullName;'Group/User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Output += New-Object -TypeName PSObject -Property $Properties
}
}
$Output | Out-GridView
解决方案
该Access
属性已映射到尝试从 SID 解析帐户身份的代码路径,因此如果您看到的是 SID 字符串而不是名称,则可能表明机器无法解析 SID。
您仍然可以尝试将单个 SID 值转换为如下[NTAccount]
对象:
$Principal = try {
$Access.IdentityReference.Translate([System.Security.Principal.NTAccount])
}
catch {
# If the translation fails we fall back to SID
$Access.IdentityReference
}
然后在属性字典中使用$Principal
代替。$Access.IdentityReference
推荐阅读
- html - 多个下拉列表绑定到一个下拉列表
- java - 使用 JavaFX 部署 NetBeans 应用程序
- javascript - 使用 JavaScript submit() 使用 Spring Boot 提交表单数据
- kotlin - 限制解决方案中使用的变量数量 - oj!算法和科特林
- python - Pandas 与同一数据框中的父 ID 联合
- python - 将上下文管理器与 psycopg2 一起使用
- spring - Spring批量动态IN查询
- graphql - 如何格式化来自 java/groovy 客户端的 NewRelic NerdGraph API 调用?
- json - 为什么当代码实际工作时 Vue 会抱怨
- flutter - Flutter中的AlignmentDirectional和AlignmentGeometry是什么