2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C#でADグループのユーザー一覧を取得する

Posted at

とある事情でADグループに所属しているユーザー一覧が欲しくなりました。
検索するとdsgetコマンドで取得できるという情報が出てくるのですが、手元の環境だとコマンドがないと言われてしまったので。
System.DirectoryServices.AccountManagement の参照が必要です。

var domainName = ""; //検索したいドメイン名
var groupName = ""; //検索したいグループ名
using (var principalContext = new PrincipalContext(ContextType.Domain, domainName))
using (var groupPrincipal = GroupPrincipal.FindByIdentity(principalContext, groupName))
{
    //名前やメールアドレスを取得できる
    var members = groupPrincipal.Members.OfType<UserPrincipal>();
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?