Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:06:47+00:00 2026-06-03T02:06:47+00:00

I am trying to use an LDAP query to return all computer objects created

  • 0

I am trying to use an LDAP query to return all computer objects created in the last 24 hours. My code currently looks like this:

//Declare new DirectoryEntry and DirectorySearcher
DirectoryEntry domainRoot = new DirectoryEntry("LDAP://rootDSE");
string rootOfDomain = domainRoot.Properties["rootDomainNamingContext"].Value.ToString();
DirectorySearcher dsSearch = new DirectorySearcher(rootOfDomain);

//Set the properties of the DirectorySearcher
dsSearch.Filter = "(&(objectClass=Computer)(whenCreated>" + dateFilter.ToString() + "))";
dsSearch.PageSize = 2000;
dsSearch.PropertiesToLoad.Add("distinguishedName");
dsSearch.PropertiesToLoad.Add("whenCreated");
dsSearch.PropertiesToLoad.Add("description");
dsSearch.PropertiesToLoad.Add("operatingSystem");
dsSearch.PropertiesToLoad.Add("name");

//Execute the search
SearchResultCollection computersFound = dsSearch.FindAll();

This code does not return any objects, and I know for certain that there have been accounts created in the last 24 hours.


EDIT: I fixed this with the following code:

GetCompList(DateTime.Now.AddDays(-1)); //This sets the filter to one day previous

//Declare new DirectoryEntry and DirectorySearcher
DirectoryEntry domainRoot = new DirectoryEntry("LDAP://rootDSE");
string rootOfDomain = domainRoot.Properties["rootDomainNamingContext"].Value.ToString();
DirectorySearcher dsSearch = new DirectorySearcher(rootOfDomain);

//Set the properties of the DirectorySearcher
dsSearch.Filter = "(&(objectClass=Computer)(whenCreated>=" + dateFilter.ToString("yyyyMMddHHmmss.sZ") + "))";
dsSearch.PageSize = 2000;
dsSearch.PropertiesToLoad.Add("distinguishedName");
dsSearch.PropertiesToLoad.Add("whenCreated");
dsSearch.PropertiesToLoad.Add("description");
dsSearch.PropertiesToLoad.Add("operatingSystem");
dsSearch.PropertiesToLoad.Add("name");


//Execute the search
SearchResultCollection computersFound = dsSearch.FindAll();

The secret is the line :

dsSearch.Filter = "(&(objectClass=Computer)(whenCreated>=" + dateFilter.ToString("yyyyMMddHHmmss.sZ") + "))";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:06:48+00:00Added an answer on June 3, 2026 at 2:06 am

    It turns out the answer was in the formatting of the whenCreated filter. According to This blogpost, the filter for whenCreated must be formatted like “yyyyMMddHHmmss.sZ”, where Z is the offset from UTC. What I did was created a method called

    private void GetCompList(DateTime dateFilter) //This overloaded version of GetCompList takes a parameter of type DateTime, and only returns computers that were built after dateFilter
        {
            try
            {
                //Convert the dateFilter to a format appropriate for an LDAP query
                int offset = -8;
                //string strDateFilter = convertToCrazyFormat(dateFilter, offset);
    
                //string strDateFilter = dateFilter.ToString("yyyyMMddhhmmss");
    
                //Declare new DirectoryEntry and DirectorySearcher
                DirectoryEntry domainRoot = new DirectoryEntry("LDAP://rootDSE");
                string rootOfDomain = domainRoot.Properties["rootDomainNamingContext"].Value.ToString();
                DirectorySearcher dsSearch = new DirectorySearcher(rootOfDomain);
    
                //Set the properties of the DirectorySearcher
                dsSearch.Filter = "(&(objectClass=Computer)(whenCreated>=" + dateFilter.ToString("yyyyMMddHHmmss.s" + offset.ToString()) + "))";
                dsSearch.PageSize = 2000;
                dsSearch.PropertiesToLoad.Add("distinguishedName");
                dsSearch.PropertiesToLoad.Add("whenCreated");
                dsSearch.PropertiesToLoad.Add("description");
                dsSearch.PropertiesToLoad.Add("operatingSystem");
                dsSearch.PropertiesToLoad.Add("name");
    

    I then call the method like this:

    GetCompList(DateTime.Now.AddDays(-1));//Pass in a negative value that represents the time period you want objects from, in this case the last day
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use python to query LDAP server, and it always returns
I am currently trying to perform an LDAP query in c++ to get the
I'm trying to use the ldap_sasl_bind_s method from the Microsoft LDAP C SDK, with
I am running a test Active directory and am trying to query with ldap.
I'm trying to use ldaptor to connect via startTLS to a LDAP server. Searching
I'm trying use this code to get image resolution from file bool GetImageSizeEx(const char
I am trying to use LDAP for authentication. I am using the OpenLDAP library
I am trying to use LDAP login to ezpublish but I am facing this
I am trying to use Spring LDAP for coding <ldap-server ldif=classpath:my-ldap-clone.ldif /> but I
I'm trying to use the library released by Novell (Novell.Directory.Ldap). Version 2.1.10. What I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.