且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在PowerShell中将SID转换为帐户名?

更新时间:2022-06-12 08:32:47

解决方案是使用 Translate()方法的translation%28v = vs.110%29.aspx rel = nofollow noreferrer> /msdn.microsoft.com/zh-cn/library/System.Security.Principal.SecurityIdentifier%28v=vs.110%29.aspx rel = nofollow noreferrer> SecurityIdentifier 类。此方法的单个参数是对您要将 SecurityIdentifier 转换为.NET类型的引用。如果检查类似的C#问题的此答案,您会发现您可以简单地传递对 System.Security.Principal。 NTAccount类

The solution is to use the Translate() method of the SecurityIdentifier class. The single parameter for this method is a reference to the .NET type that you would like to convert the SecurityIdentifier to. If you examine this answer to the similar C# question, you will see that you can simply pass in a reference to the System.Security.Principal.NTAccount class.

结果代码如下:

$Identity = [System.Security.Principal.WindowsIdentity]::GetCurrent();
foreach ($Group in $Identity.Groups) {
    $Group.Translate([System.Security.Principal.NTAccount]).Value;
}