Getting Domain listing in C#, Net view /domain
I am trying to get a list of all the domains on my network (Command line is net view /domain)
Forest currentForest = Forest.GetCurrentForest();
DomainCollection domains = currentForest.Domains;
foreach (Domain objDomain in domains)
{
Console.WriteLine(objDomain.Name);
}
This is not returning anything even close to t开发者_高级运维he net view /domain. What is the difference here between the two?
The difference is that the net view /domain lists all of the domains and workgroups that are on the network (or the network segment you are on at least). In contrast, the code you listed above will give you all of the domains that are in your current forest. That means it is only looking at the forest you are currently a part of, not all possible domains (and workgroups) that are on the network.
精彩评论