I made a small program to add a user to a group for a while. I want to display the users of the group in the DataGridView. I want to know when the user leaves the group. I can find this out from powershell.
Get-ADGroup -Identity "UG_TS_CISCO" -Properties members -ShowMemberTimeToLive
****************
Members : {<TTL=204236>,CN=Ilya Evseev,***, <TTL=31412>,CN=Vasyan Pupkin,***}
DirectoryEntry dc = new DirectoryEntry();
DirectorySearcher searcher= new DirectorySearcher(dc);
searcher.Filter = ("(&(objectCategory=group)(cn=UG_TS_CISCO))");
foreach (SearchResult src in searcher.FindAll()) {
DirectoryEntry groupEntry = src.GetDirectoryEntry();
object members = groupEntry.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
dataGridView.Rows.Add(member.Properties["name"][0], member.Properties["sAMAccountName"][0]);
}
}
But how to get this data from the application using DirectoryServices I can't understand.