【发布时间】:2014-05-08 05:16:22
【问题描述】:
我在 Windows 7 上使用 PowerShell。我有以下代码 sn-p 并想知道
为什么我没有将 SID 转换为友好的用户名(在域上)?
$OutFile = "I:\Permissions.csv"
$RootPath = "K:\FolderName"
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
foreach ($Folder in $Folders)
{
$ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access }
Foreach ($ACL in $ACLs)
{
$objSID = New-Object System.Security.Principal.SecurityIdentifier($ACL.IdentityReference.Value)
#$objUser = $objSID.Translate([System.Security.Principal.NTAccount])
$objUser = $objSID.Translate([System.Security.Principal.SecurityIdentifier])
$objUser.Value
#Show User
Write-Host “`r`nThe user mapped to SID $($objSID) is $($objUser.value)`r`n” -f “Red”
$OutInfo = $Folder.Fullname + "," + $objUser.Value + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
Add-Content -Value $OutInfo -Path $OutFile
}
}
所需的输出将是 SAM 帐户名称。 (不是显示名称)
John.Smith1
John.Smith
【问题讨论】:
-
请提供工作样本。
$ACL从未被声明过。 -
给你。你怎么看?
-
更好,仍然缺少
$Dname和$outfile,但我创建了一个虚拟对象来解决这个问题。查看更新的答案。 -
$DName 是我根据以下答案尝试的。
-
.IdentityReference.Value应该已经提供了一个“友好的用户名”。您为什么要尝试将其转换为 SID,然后再转换回用户名?实际和期望输出的示例会有所帮助。
标签: windows powershell windows-7 powershell-2.0