简体   繁体   English

从SID获取非Windows 2000之前的组名

[英]Get Non Pre-Windows 2000 Group Name from SID

I have a SID which represents a group on a different domain. 我有一个SID,代表另一个域上的组。

I am trying to get the group name using: 我正在尝试使用以下方式获取组名:

$objSid = New-Object 'System.Security.Principal.SecurityIdentifier'($Sid)
$objUser = $objSid.Translate([System.Security.Principal.NTAccount])
$groupName = $objUser.Value

However this returns the pre-Windows 2000 name which is different to the actual group name (it has A_ at the front). 但是,这将返回Windows 2000以前的名称,该名称与实际的组名称不同(它的前面有A_ )。

How can I get the real group name instead of the pre-Windows 2000 group name? 如何获得真实的组名而不是Windows 2000之前的组名?

EDIT: iRon mentioned I can use (Get-ADGroup $GroupName).Name , however I now need to write this in C#. 编辑:iRon提到我可以使用(Get-ADGroup $GroupName).Name ,但是我现在需要用C#编写它。 The first part is easy to translate, however how can I get the C# code for the Get-ADGroup commandlet? 第一部分很容易翻译,但是如何获得Get-ADGroup的C#代码?

Turns out the pre-Windows 2000 name is just the samAccountName. 原来Windows 2000以前的名称只是samAccountName。 So to get the group name, you just need to search for the group with samAccountName = pre-Windows 2000 name. 因此,要获取组名,您只需使用samAccountName = Windows 2000以前的名称搜索该组。 This can easily be done in C# using DirectorySearcher. 使用DirectorySearcher在C#中可以轻松完成此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM