static void Main(string[] args) { Console.WriteLine("ListAllGroupsViaTokenGroups:"); var result = new List <string>(); var creds = new Credentials { DomainName = "home.local", Username = "******", Password = "******" }; var searcher = new ActiveDirectorySearcher(creds); try { var groups = searcher.GetGroups("bla"); result = searcher.GetAllOUs(); foreach (var group in result) { Console.WriteLine($" --- {group} ---"); var users = searcher.GetUsersFromUnit(group); foreach (var user in users) { Console.WriteLine(user.DisplayName); } } } catch (Exception exc) { Console.WriteLine(exc.Message); } Console.Read(); }
public FrmMain(Credentials creds) { this.InitializeComponent(); this.creds = creds; this.searcher = new ActiveDirectorySearcher(this.creds); var ous = this.searcher.GetAllOUs(); foreach (var ou in ous) { this.LbxOrgUnits.Items.Add(ou); } }