我在Windows 7上使用PowerShell。我有以下代码片段,想知道
为什么我没有让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
我正在Windows 7上使用PowerShell。我有以下代码片段,想知道为什么我没有将SID转换为友好的用户名(在域上)? $ OutFile =“ I:\ Permissions ....
您可以使用相当简单的ADSI查找来提取用户的专有名称。试试看:
IdentityReference
是SecurityIdentifier
对象或NTAccount
对象,而不是作为字符串的SID值,这是SecurityIdentifier
构造函数所需要的。如果需要以字符串形式访问SID,则需要访问$ACL.IdentityReference.Value
。
将SID字符串转换为NTAccount: