Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

AD DirectorySearcher Syntax

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 03-09-2007   #1 (permalink)
Stephen Merkel
Guest


 

AD DirectorySearcher Syntax

I am looking to return results from AD containing user accounts created since
a given date.
I believe that I am close with something like this:

$searcher=New-object DirectoryServices.DirectorySearcher
$searcher.Filter="(&(objectcategory=person)(objectclass=user)(whenCreated >
$date)"
$results = $searcher.FindAll()

When $date contains a something like $date = get-date -year 2007 -month 02
-day 15, (i.e about three weeks ago) I get an error indicating a problem with
the filter

I haven't been able to straightened out this syntax yet.

Any help would be appreciated

--
Merkel-DBA

My System SpecsSystem Spec
Old 03-09-2007   #2 (permalink)
RichS
Guest


 

RE: AD DirectorySearcher Syntax

The ldap filter syntax doesn't contain a > operator. You have to use >=
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Stephen Merkel" wrote:

> I am looking to return results from AD containing user accounts created since
> a given date.
> I believe that I am close with something like this:
>
> $searcher=New-object DirectoryServices.DirectorySearcher
> $searcher.Filter="(&(objectcategory=person)(objectclass=user)(whenCreated >
> $date)"
> $results = $searcher.FindAll()
>
> When $date contains a something like $date = get-date -year 2007 -month 02
> -day 15, (i.e about three weeks ago) I get an error indicating a problem with
> the filter
>
> I haven't been able to straightened out this syntax yet.
>
> Any help would be appreciated
>
> --
> Merkel-DBA

My System SpecsSystem Spec
Old 03-09-2007   #3 (permalink)
Lance
Guest


 

Re: AD DirectorySearcher Syntax

On Mar 9, 10:23 am, Stephen Merkel
<StephenMer...@discussions.microsoft.com> wrote:
> I am looking to return results from AD containing user accounts created since
> a given date.
> I believe that I am close with something like this:
>
> $searcher=New-object DirectoryServices.DirectorySearcher
> $searcher.Filter="(&(objectcategory=person)(objectclass=user)(whenCreated >
> $date)"
> $results = $searcher.FindAll()
>
> When $date contains a something like $date = get-date -year 2007 -month 02
> -day 15, (i.e about three weeks ago) I get an error indicating a problem with
> the filter
>
> I haven't been able to straightened out this syntax yet.
>
> Any help would be appreciated
>
> --
> Merkel-DBA


get-ldap -server testboy -cred $ldapcred -dn "cn=Users,dc=JUNGLE" -
search "(&(objectcategory=person)(objectClass
=user)(whenCreated <= $threeweeksago))" -attr

(this uses get-ldap from NetCmdlets)

Lance

My System SpecsSystem Spec
Old 03-10-2007   #4 (permalink)
RichS
Guest


 

Re: AD DirectorySearcher Syntax

could also try the get-adobject from pscx
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Lance" wrote:

> On Mar 9, 10:23 am, Stephen Merkel
> <StephenMer...@discussions.microsoft.com> wrote:
> > I am looking to return results from AD containing user accounts created since
> > a given date.
> > I believe that I am close with something like this:
> >
> > $searcher=New-object DirectoryServices.DirectorySearcher
> > $searcher.Filter="(&(objectcategory=person)(objectclass=user)(whenCreated >
> > $date)"
> > $results = $searcher.FindAll()
> >
> > When $date contains a something like $date = get-date -year 2007 -month 02
> > -day 15, (i.e about three weeks ago) I get an error indicating a problem with
> > the filter
> >
> > I haven't been able to straightened out this syntax yet.
> >
> > Any help would be appreciated
> >
> > --
> > Merkel-DBA

>
> get-ldap -server testboy -cred $ldapcred -dn "cn=Users,dc=JUNGLE" -
> search "(&(objectcategory=person)(objectClass
> =user)(whenCreated <= $threeweeksago))" -attr
>
> (this uses get-ldap from NetCmdlets)
>
> Lance
>
>

My System SpecsSystem Spec
Old 03-11-2007   #5 (permalink)
Flowering Weeds
Guest


 

Re: AD DirectorySearcher Syntax


>> $searcher=New-object DirectoryServices.DirectorySearcher


> get-ldap -server testboy -cred $ldapcred -dn


> could also try the get-adobject from pscx


PS> logparser -h -i:ads

Input format: ADS (Active Directory)
Returns properties of Active Directory objects



My System SpecsSystem Spec
Old 03-12-2007   #6 (permalink)
Gaurhoth
Guest


 

Re: AD DirectorySearcher Syntax

You need to convert the Date into a format that the LDAP filter recognizes for whenCreated field. Also, as mentioned, you should use ">=", not ">". See example below:

$past = [datetime]::UtcNow.adddays(-15)
$ldappast = "{0:0000}{1:00}{2:00}0000000Z" -f $g.year,$g.month,$g.day
$s = new-object directoryservices.directorysearcher([ADSI]'')
$s.filter = "(&(objectcategory=person)(objectclass=user)(whenCreated>=$ldappast))"
$s.findall()

LDAP date filters expect a format of:
YYYYMMDDHHMMSS.Z

Example for March 12, 2007:
20070312000000.0Z
I've filled in 0's for Hours, minutes, seconds since I don't care.
0Z indicates UTC.



"Stephen Merkel" <StephenMerkel@discussions.microsoft.com> wrote in message news:5426F595-2289-40F1-B740-485F3E33D629@microsoft.com...
>I am looking to return results from AD containing user accounts created since
> a given date.
> I believe that I am close with something like this:
>
> $searcher=New-object DirectoryServices.DirectorySearcher
> $searcher.Filter="(&(objectcategory=person)(objectclass=user)(whenCreated >
> $date)"
> $results = $searcher.FindAll()
>
> When $date contains a something like $date = get-date -year 2007 -month 02
> -day 15, (i.e about three weeks ago) I get an error indicating a problem with
> the filter
>
> I haven't been able to straightened out this syntax yet.
>
> Any help would be appreciated
>
> --
> Merkel-DBA

My System SpecsSystem Spec
Old 03-12-2007   #7 (permalink)
Gaurhoth
Guest


 

Re: AD DirectorySearcher Syntax

Sorry, there is a typo in the second line. Change it to read as follows:
$ldappast = "{0:0000}{1:00}{2:00}000000.0Z" -f $g.year,$g.month,$g.day

It was missing a Period just before 0Z.
"Gaurhoth" <gaurhoth@live.com> wrote in message news:9AA01174-40F2-406E-A220-61D93894B8C2@microsoft.com...
You need to convert the Date into a format that the LDAP filter recognizes for whenCreated field. Also, as mentioned, you should use ">=", not ">". See example below:

$past = [datetime]::UtcNow.adddays(-15)
$ldappast = "{0:0000}{1:00}{2:00}0000000Z" -f $g.year,$g.month,$g.day
$s = new-object directoryservices.directorysearcher([ADSI]'')
$s.filter = "(&(objectcategory=person)(objectclass=user)(whenCreated>=$ldappast))"
$s.findall()

LDAP date filters expect a format of:
YYYYMMDDHHMMSS.Z

Example for March 12, 2007:
20070312000000.0Z
I've filled in 0's for Hours, minutes, seconds since I don't care.
0Z indicates UTC.



"Stephen Merkel" <StephenMerkel@discussions.microsoft.com> wrote in message news:5426F595-2289-40F1-B740-485F3E33D629@microsoft.com...
>I am looking to return results from AD containing user accounts created since
> a given date.
> I believe that I am close with something like this:
>
> $searcher=New-object DirectoryServices.DirectorySearcher
> $searcher.Filter="(&(objectcategory=person)(objectclass=user)(whenCreated >
> $date)"
> $results = $searcher.FindAll()
>
> When $date contains a something like $date = get-date -year 2007 -month 02
> -day 15, (i.e about three weeks ago) I get an error indicating a problem with
> the filter
>
> I haven't been able to straightened out this syntax yet.
>
> Any help would be appreciated
>
> --
> Merkel-DBA

My System SpecsSystem Spec
Old 03-13-2007   #8 (permalink)
Stephen Merkel
Guest


 

Re: AD DirectorySearcher Syntax

Thank you very much, the format of the date was the missing piece I have been
looking for!
--
Merkel-DBA


"Gaurhoth" wrote:

> Sorry, there is a typo in the second line. Change it to read as follows:
> $ldappast = "{0:0000}{1:00}{2:00}000000.0Z" -f $g.year,$g.month,$g.day
>
> It was missing a Period just before 0Z.
> "Gaurhoth" <gaurhoth@live.com> wrote in message
> news:9AA01174-40F2-406E-A220-61D93894B8C2@microsoft.com...
> You need to convert the Date into a format that the LDAP filter
> recognizes for whenCreated field. Also, as mentioned, you should use ">=",
> not ">". See example below:
>
> $past = [datetime]::UtcNow.adddays(-15)
> $ldappast = "{0:0000}{1:00}{2:00}0000000Z" -f $g.year,$g.month,$g.day
> $s = new-object directoryservices.directorysearcher([ADSI]'')
> $s.filter =
> "(&(objectcategory=person)(objectclass=user)(whenCreated>=$ldappast))"
> $s.findall()
>
> LDAP date filters expect a format of:
> YYYYMMDDHHMMSS.Z
>
> Example for March 12, 2007:
> 20070312000000.0Z
> I've filled in 0's for Hours, minutes, seconds since I don't care.
> 0Z indicates UTC.
>
>
>
> "Stephen Merkel" <StephenMerkel@discussions.microsoft.com> wrote in
> message news:5426F595-2289-40F1-B740-485F3E33D629@microsoft.com...
> >I am looking to return results from AD containing user accounts created

> since
> > a given date.
> > I believe that I am close with something like this:
> >
> > $searcher=New-object DirectoryServices.DirectorySearcher
> >

> $searcher.Filter="(&(objectcategory=person)(objectclass=user)(whenCreated
> >
> > $date)"
> > $results = $searcher.FindAll()
> >
> > When $date contains a something like $date = get-date -year

> 2007 -month 02
> > -day 15, (i.e about three weeks ago) I get an error indicating a

> problem with
> > the filter
> >
> > I haven't been able to straightened out this syntax yet.
> >
> > Any help would be appreciated
> >
> > --
> > Merkel-DBA

>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
robocopy syntax littleriver Vista General 3 02-01-2008 10:37 AM
"invalid STORE command syntax invalid message set syntax" Catullus Nacakus Vista mail 6 01-26-2008 05:46 PM
Using .reg file syntax Marco Shaw PowerShell 5 06-06-2007 05:54 PM
need syntax carmine934 Vista hardware & devices 0 06-02-2007 12:03 PM
[ADSI] Syntax Chris Warwick PowerShell 8 09-30-2006 12:13 AM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008