骨のダイスを転がそう
2010-11-08
_ [.Net] ADに接続して、グループの所属を確認
System.DirectoryServices.AccountManagement を参照に加えておいて、using で名前空間をインポート。
using ( PrincipalContext ctx = new PrincipalContext( ContextType.Domain, "HOGE", "OU=FUGA,DC=hoge,DC=or,DC=jp", "hogehoge", "fugafuga") ) { GroupPrincipal g = GroupPrincipal.FindByIdentity(ctx, "admins"); UserPrincipal u = UserPrincipal.FindByIdentity(ctx, @"HOGE\foobar"); if (g != null) { Console.WriteLine(u.IsMemberOf(g).ToString()); foreach (var n in g.Members) { Console.WriteLine(n.DisplayName); } } else { Console.WriteLine("グループが見付かりませんでした。"); } }
[ツッコミを入れる]