EDN Admin
Well-known member
<pre> Console.WriteLine("Enter server:");
string sServer = Console.ReadLine();
Console.WriteLine("Enter account:");
string sAccount = Console.ReadLine();
Console.WriteLine("Enter password:");
//string sPassword = Console.ReadLine();
string sPassword = ReadPassword();
//Console.WriteLine("Enter search4:");
//string sSubscriber = Console.ReadLine();
try
{
DirectoryEntry searchroot = new DirectoryEntry("LDAP://" + sServer, sAccount, sPassword);
DirectorySearcher ds = new DirectorySearcher(searchroot);
ds.SearchScope = SearchScope.Subtree;
ds.Filter = "(&(objectClass=*)(cn=" + sUser + "))";
//SearchResultCollection results = ds.FindAll();
//string sResult = results.Count.ToString();
/*foreach (SearchResult result in ds.FindAll())
{
string legacyexchangedn = null;
if (result != null)
{
DirectoryEntry de = result.GetDirectoryEntry();
string cn = de.Properties["cn"].Value.ToString();
if (de.Properties["legacyexchangedn"].Value != null)
{
legacyexchangedn = de.Properties["legacyexchangedn"].Value.ToString();
Console.WriteLine("LegacyExchangeDN = " + legacyexchangedn);
}
}
}*/
SearchResult result = ds.FindOne();
sResult = result.Properties.Count.ToString();
string legacyexchangedn = null;
if (result != null)
{
DirectoryEntry de = result.GetDirectoryEntry();
string cn = de.Properties["cn"].Value.ToString();
if (de.Properties["legacyexchangedn"].Value != null)
{
legacyexchangedn = de.Properties["legacyexchangedn"].Value.ToString();
Console.WriteLine("LegacyExchangeDN = " + legacyexchangedn);
}
}
}
catch (Exception er)
{
Console.WriteLine("Error in get directory entry data.");
string msg = "rnSource:rnt" + er.Source + "rn" +
"Stack trace:rnt" + er.StackTrace + "rn" +
"Path: rnt" + er.TargetSite + "rn" +
"Message:rnt" + er.Message + "rn" +
"Data:rnt" + er.Data + "rn" +
"Error:rnt" + er.ToString() + "rn";
Console.WriteLine(msg);
Console.WriteLine("Result count = " + sResult);
}
[/code]
<br/>
im trying to create a C# program to query the domain to find a single user to read what is being created in the "LegacyExchangeDN" object.
im running into a problem where i cant figure out how to make it work in production domain. of course it works find in my lab but always fail in the real domain.
i get this msg:
Source:<br/>
System.DirectoryServices<br/>
Stack trace:<br/>
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)<br/>
at System.DirectoryServices.DirectoryEntry.Bind()<br/>
at System.DirectoryServices.DirectoryEntry.get_AdsObject()<br/>
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)<br/>
at System.DirectoryServices.DirectorySearcher.FindOne()<br/>
at getAD.Program.test8(Boolean isXPR64)<br/>
Path:<br/>
Void Bind(Boolean)<br/>
Message:<br/>
The server is not operational.
Data:<br/>
System.Collections.ListDictionaryInternal<br/>
Error:<br/>
System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)<br/>
at System.DirectoryServices.DirectoryEntry.Bind()<br/>
at System.DirectoryServices.DirectoryEntry.get_AdsObject()<br/>
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)<br/>
at System.DirectoryServices.DirectorySearcher.FindOne()<br/>
at getAD.Program.test8(Boolean isXPR64)
no matter what server i use i cant seem to get past this error.
i have tried different servers, domain string.
the production domain has well over 6000 users.
any idea?
View the full article
string sServer = Console.ReadLine();
Console.WriteLine("Enter account:");
string sAccount = Console.ReadLine();
Console.WriteLine("Enter password:");
//string sPassword = Console.ReadLine();
string sPassword = ReadPassword();
//Console.WriteLine("Enter search4:");
//string sSubscriber = Console.ReadLine();
try
{
DirectoryEntry searchroot = new DirectoryEntry("LDAP://" + sServer, sAccount, sPassword);
DirectorySearcher ds = new DirectorySearcher(searchroot);
ds.SearchScope = SearchScope.Subtree;
ds.Filter = "(&(objectClass=*)(cn=" + sUser + "))";
//SearchResultCollection results = ds.FindAll();
//string sResult = results.Count.ToString();
/*foreach (SearchResult result in ds.FindAll())
{
string legacyexchangedn = null;
if (result != null)
{
DirectoryEntry de = result.GetDirectoryEntry();
string cn = de.Properties["cn"].Value.ToString();
if (de.Properties["legacyexchangedn"].Value != null)
{
legacyexchangedn = de.Properties["legacyexchangedn"].Value.ToString();
Console.WriteLine("LegacyExchangeDN = " + legacyexchangedn);
}
}
}*/
SearchResult result = ds.FindOne();
sResult = result.Properties.Count.ToString();
string legacyexchangedn = null;
if (result != null)
{
DirectoryEntry de = result.GetDirectoryEntry();
string cn = de.Properties["cn"].Value.ToString();
if (de.Properties["legacyexchangedn"].Value != null)
{
legacyexchangedn = de.Properties["legacyexchangedn"].Value.ToString();
Console.WriteLine("LegacyExchangeDN = " + legacyexchangedn);
}
}
}
catch (Exception er)
{
Console.WriteLine("Error in get directory entry data.");
string msg = "rnSource:rnt" + er.Source + "rn" +
"Stack trace:rnt" + er.StackTrace + "rn" +
"Path: rnt" + er.TargetSite + "rn" +
"Message:rnt" + er.Message + "rn" +
"Data:rnt" + er.Data + "rn" +
"Error:rnt" + er.ToString() + "rn";
Console.WriteLine(msg);
Console.WriteLine("Result count = " + sResult);
}
[/code]
<br/>
im trying to create a C# program to query the domain to find a single user to read what is being created in the "LegacyExchangeDN" object.
im running into a problem where i cant figure out how to make it work in production domain. of course it works find in my lab but always fail in the real domain.
i get this msg:
Source:<br/>
System.DirectoryServices<br/>
Stack trace:<br/>
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)<br/>
at System.DirectoryServices.DirectoryEntry.Bind()<br/>
at System.DirectoryServices.DirectoryEntry.get_AdsObject()<br/>
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)<br/>
at System.DirectoryServices.DirectorySearcher.FindOne()<br/>
at getAD.Program.test8(Boolean isXPR64)<br/>
Path:<br/>
Void Bind(Boolean)<br/>
Message:<br/>
The server is not operational.
Data:<br/>
System.Collections.ListDictionaryInternal<br/>
Error:<br/>
System.Runtime.InteropServices.COMException (0x8007203A): The server is not operational.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)<br/>
at System.DirectoryServices.DirectoryEntry.Bind()<br/>
at System.DirectoryServices.DirectoryEntry.get_AdsObject()<br/>
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)<br/>
at System.DirectoryServices.DirectorySearcher.FindOne()<br/>
at getAD.Program.test8(Boolean isXPR64)
no matter what server i use i cant seem to get past this error.
i have tried different servers, domain string.
the production domain has well over 6000 users.
any idea?
View the full article