Trypsim
asked on
Store Active Directory Querry into a Multidimensional array
Essentially I want to query 2 domain controllers in AD and compare the information between the two. I only need to be able to store the HostName and Last Login time stamp from each Domain Controller. I would like to modify the code to return the array to the calling function.
I------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---
private void Button_1_Click(object sender, EventArgs e)
{
string OUDN = txtTargetList_Path.Text;
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://" + OUDN);
DirectorySearcher DirSearch = new DirectorySearcher(entry);
DirSearch.Filter = "(objectClass=computer)";
DirSearch.PageSize = 100000;
foreach(SearchResult results in DirSearch.FindAll())
{
string Line = "";
string HName = "";
string LstLgn = "";
foreach(string Value in results.Properties.Propert yNames)
{
if(results.Properties[Valu e]!=null)
{
if (Value == "name")
{
HName = (string)results.Properties [Value][0] ;
}
if(Value == "lastlogon")
{
long lastLogon = (long)results.Properties[V alue][0];
LstLgn = DateTime.FromFileTime(last Logon).ToS tring();
}
}
}
Line = HName + "," + LstLgn;
listBox1.Items.Add(Line);
}
}
catch (IOException Iox)
{
lstErrorLog.Items.Add(Iox. Data.ToStr ing());
}
catch (DirectoryServicesCOMExcep tion ex)
{
lstErrorLog.Items.Add(ex.M essage.ToS tring());
}
}
I-------------------------
private void Button_1_Click(object sender, EventArgs e)
{
string OUDN = txtTargetList_Path.Text;
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://" + OUDN);
DirectorySearcher DirSearch = new DirectorySearcher(entry);
DirSearch.Filter = "(objectClass=computer)";
DirSearch.PageSize = 100000;
foreach(SearchResult results in DirSearch.FindAll())
{
string Line = "";
string HName = "";
string LstLgn = "";
foreach(string Value in results.Properties.Propert
{
if(results.Properties[Valu
{
if (Value == "name")
{
HName = (string)results.Properties
}
if(Value == "lastlogon")
{
long lastLogon = (long)results.Properties[V
LstLgn = DateTime.FromFileTime(last
}
}
}
Line = HName + "," + LstLgn;
listBox1.Items.Add(Line);
}
}
catch (IOException Iox)
{
lstErrorLog.Items.Add(Iox.
}
catch (DirectoryServicesCOMExcep
{
lstErrorLog.Items.Add(ex.M
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, this is exactly what I was looking for.
ASKER
al.Add(new Data(HName, LstLgn));
Returns 3 errors when I compile it? I think that I am missing a Library. Can you please help with this too?
Error 1 The type or namespace name 'data' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\S QT.cs 4433 32 SITS-SQT
Thanks,
Returns 3 errors when I compile it? I think that I am missing a Library. Can you please help with this too?
Error 1 The type or namespace name 'data' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\tcbea\Desktop\VS Projects Nathan\SITS-SQT\SITS-SQT\S
Thanks,
Open in new window