james_martin
asked on
Filter VB.NET AD request by whenCreated
I have program that will allow some end-users to export some data from AD. The problem I am running into is with my search code for the "whenCreate" field. I am trying to export last 7 Days, 14 Days, and 30 Days worth of data, but just cant seem to get it to work.
mySearcher.Filter = "(&(objectClass=User)(when Created=To day.Now - 7))"
mySearcher.Filter = "(&(objectClass=User)(when
Hi james_martin,
please try this code(snippet)
thanks
please try this code(snippet)
thanks
mySearcher.Filter = "(&(objectCategory=user)(whencreated>=Today.Now - 7))"
ASKER
Chris,
This declaration "Dim RegExp As New Regex("-|:| ")" is giving me an issue; "Regex" is back as not defined, how should I define it?
Thanks.
This declaration "Dim RegExp As New Regex("-|:| ")" is giving me an issue; "Regex" is back as not defined, how should I define it?
Thanks.
Sorry... Needs the namespace importing:
Imports System.Text.RegularExpress
Otherwise it won't like it :)
Chris
Oh and I forgot the -7 days part, it'll need adding back in. Got distracted ;)
Chris
And I neglected to put in the "how to find a days worth" bit. Have the code generate something like this:
(&(objectClass=User)(whenC
Then you get those in the specified range :)
Chris
ASKER
Chris,
Is this the correct use?
mySearcher.Filter = "(&(objectClass=User)(when Created<=" & dateString(-7) & "))"
Is this the correct use?
mySearcher.Filter = "(&(objectClass=User)(when
ASKER
sorry it reformatted it.
mySearcher.Filter = "(&(objectClass=User)(whenCreated<=" & dateString(-7) & "))"
Not if you used mine above, dateString is a String so can't use date functions on it any more. The -7 needs to be done to the date prior to converting to a universal date string (.ToString("u")).
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Limited knowledge huh???? Well you rock and thanks very much!
Hey,
The date you use must be in Universal Time format:
yyyymmddhhnnss.0Z
Perhaps like this (but there may well be much more efficient ways):
Dim dateString As String = Date.Now.ToString("u")
Dim RegExp As New Regex("-|:| ")
dateString = RegExp.Replace(dateString,
dateString = dateString.Replace("Z", ".0Z")
Console.WriteLine(dateStri
You're also unlikely to get an exact match on that, many many seconds in the day and you'd have to be down to that. So this...
"(&(objectClass=User)(when
Or this:
"(&(objectClass=User)(when
Chris