|
I'm tryinig to recurse through the objects under a specific Organization Unit.
string domain = "LDAP://DC=MyCompany,DC=com";
string serverName = "192.168.30.10";
string ou = "OU=OrgUnit-Test-1,DC=MyCompany,DC=com";
I already know that under the OU above there are other OU's, Groups, and users. Each child OU can have groups and users, and each group can have users. It's a hierarchy of info that I want to interate over.
All the examples I'm finding are about finding users in groups and the like. What I'ds really like is some way of looping over some objects to examine them.
Here's an example I have that finds users in a specific group:
<pre>public List<ActiveDirectoryUser> GetAllUsersInGroup(string domainName, string groupName)
{
List<ActiveDirectoryUser> results = new List<ActiveDirectoryUser>();
using (var context = new PrincipalContext(ContextType.Domain, domainName))
{
using (var group = GroupPrincipal.FindByIdentity(context, groupName))
{
if (group != null)
{
var users = group.GetMembers(true).ToList();
foreach (UserPrincipal user in users)
{
var adu = new ActiveDirectoryUser(user.DisplayName, user.UserPrincipalName, user.GivenName, user.Surname, user.EmailAddress, user.Enabled.Value);
results.Add(adu);
}
}
}
}
return results;
}
This works fine - if you know the group name.
Is there any way, given a starting OU, to examine all child objects under it? Again, I need to examine the entire hierarchy.
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 13-Jul-20 16:37pm.
|
|
|
|
|
Does this SO answer help?
c# - Get Groups From OU using DirectoryServices.AccountManagement - Stack Overflow[^]
using (var yourOU = new PrincipalContext(ContextType.Domain, "mycompany.local", "OU=Marketing,OU=Operations,OU=Applications,DC=mycompany,DC=local"))
using (var findAllGroups = new GroupPrincipal(yourOU, "*"))
using (var ps = new PrincipalSearcher(findAllGroups))
{
foreach(var group in ps.FindAll())
{
...
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Does this SO answer help?
Only partly. I already have something like this that gives back groups for an OU. What's missing is child OU's. An OU can havee other OU's under it.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
active directory - How to get list of OU using AccountManagement (C#) - Stack Overflow[^]
You can extend the GroupPrincipal to search for OUs:
[DirectoryRdnPrefix("OU")]
[DirectoryObjectClass("organizationalUnit")]
public class OuPrincipal : GroupPrincipal
{
public OuPrincipal(PrincipalContext context) : base(context)
{
}
} You should then be able to use this in a similar way to the other code to find the child OUs.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
which website learn and solution C# window Application >
|
|
|
|
|
Um. This one?
Sorry, but your question is so vague that we can't really give any other answer (except "try Google.com", and you probably used that one to find this one ...)
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I thought: how does he come up with a handle like "knowledge share"; then I realized it was "knowedge"
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
|
None of them. The quickest way to learn is going to be books.
Websites just don't convey the level of detail and expansive coverage of the subject the way books do.
|
|
|
|
|
And the worst way is via YouTube. Even "get a copy of VS and start guessing the syntax" is better than most of them...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
|
Straightforward question for you gurus
AddressOrDNSName = "The dynamic DNS name given by my ASUS router"
This works perfectly on my Win 10 laptop connected with wifi to my LAN
IPAddress ipaddress = Dns.GetHostAddresses(AddressOrDNSName).FirstOrDefault();
But errors on my Win 10 Surface Pro connected with WiFi to my LAN with "No such host is known"
WTF ?
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Are you sure the Surface Pro is configured correctly for Dns?
|
|
|
|
|
It's strange Richard because I can ping it from the command line on the Surface - what do you mean by configured correctly for DNS ?
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Sorry Pete my mistake, I was thinking in pre-WiFi terms. DNS is managed in the router.
|
|
|
|
|
Try querying / refreshing the "arp cache".
arp | Microsoft Docs
And Ipconfig refreshes DHCP/DNS settings.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
modified 12-Jul-20 13:01pm.
|
|
|
|
|
The code below is for dicovering Logitech Media Servers running on my LAN
It works perfectly unless I have a server listening on the same pc ( Windows 10 ) as this code is running on.
It fails with "Only one usage of each socket address is normally allowed"
I have several of these servers running on my LAN and if I stop the one on my pc they are all found without error
int UDPPORT = 3483;
IPEndPoint ReceiveIP = new IPEndPoint(IPAddress.Broadcast,UDPPORT);
UdpClient ClientListener = new UdpClient(UDPPORT);
any ideas guys ?
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
modified 10-Jul-20 8:18am.
|
|
|
|
|
You cannot have multiple applications running on one system trying to listen on the same port.
|
|
|
|
|
Ok so that's why it works if the server is on a different box on the LAN
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Exactly. A socket is like a telephone, it has a unique address (IP and port), and only one process can have the number at any one time. So if you have two processes on the same PC both listening on the same port, which one should be given the connection when a message arrives?
|
|
|
|
|
That's easy. You told the code to listen on a port that is already being used by another process.
Two processes cannot listen on the same port, be it another app entirely, or multiple instances of your app.
|
|
|
|
|
I see thanks
"We can't stop here - this is bat country" - Hunter S Thompson - RIP
|
|
|
|
|
Or you use a "proxy"; one "port" listener that forwards to your other listening "subscribers", depending on content.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Console.WriteLine("-----Enter at least 10 numbers-----");
int[] num = new int[10];
int input = 0;
while (input <= 10)
{
Console.Write("Enter a whole number: ");
num[input] = Convert.ToInt32(Console.ReadLine());
input++;
}
Console.Write("\nThis are the list of Even Numbers: ");
int Even = 0;
while (Even < 10)
{
if (num[input] % 2 == 0)
Console.Write(num[input]);
Even++;
}
Console.Write("\nThis are the list of your Odd Numbers: ");
int Odd = 0;
while (Odd < 10)
{
if (num[input] % 2 == 1)
Console.Write(num[input]);
Odd++;
}
Console.ReadLine();
|
|
|
|