首页 > 解决方案 > 在网络驱动器组/用户名中获取 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

标签: bashpowershellshellnetworking

解决方案


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


推荐阅读