Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - help with LDAP query

Reply
 
Old 03-10-2008   #1 (permalink)
Ben Christian


 
 

help with LDAP query

I'm trying to do an LDAP query to find all machines ENDING with a specific
string. I have no problem finding machines with a prefix, but i can't seem
to get the suffix working right. Here's what I'm trying...

get-qadcomputer -LdapFilter '(SamAccountName=*end)'

i actually want to get all pcs matching a beginning AND end...for example

get-qadcomputer -LdapFilter '(&(SamAccountName=start*)(SamAccountName=*end))'

and hopefully that would return all computers matching "start*end" like:
start123567end
start123end
etc.

So...i can't even get the suffix alone to work...who can tell me what i'm
doing wrong?


Thanks!!


My System SpecsSystem Spec
Old 03-10-2008   #2 (permalink)
Brandon Shell [MVP]


 
 

Re: help with LDAP query

Try this. Most computer sAMAccountName have $ at the end.

get-qadcomputer -LdapFilter '(&(sAMAccountName=start*)(sAMAccountName=*end$))'

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

BC> I'm trying to do an LDAP query to find all machines ENDING with a
BC> specific string. I have no problem finding machines with a prefix,
BC> but i can't seem to get the suffix working right. Here's what I'm
BC> trying...
BC>
BC> get-qadcomputer -LdapFilter '(SamAccountName=*end)'
BC>
BC> i actually want to get all pcs matching a beginning AND end...for
BC> example
BC>
BC> get-qadcomputer -LdapFilter
BC> '(&(SamAccountName=start*)(SamAccountName=*end))'
BC>
BC> and hopefully that would return all computers matching "start*end"
BC> like:
BC> start123567end
BC> start123end
BC> etc.
BC> So...i can't even get the suffix alone to work...who can tell me
BC> what i'm doing wrong?
BC>
BC> Thanks!!
BC>


My System SpecsSystem Spec
Old 03-10-2008   #3 (permalink)
Shay Levi


 
 

Re: help with LDAP query


Although Brandon's query is much more efficient, being processed on the server
side, you can simply use wildcard characters:


PS > get-qadcomputer -name start*end


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I'm trying to do an LDAP query to find all machines ENDING with a
> specific string. I have no problem finding machines with a prefix,
> but i can't seem to get the suffix working right. Here's what I'm
> trying...
>
> get-qadcomputer -LdapFilter '(SamAccountName=*end)'
>
> i actually want to get all pcs matching a beginning AND end...for
> example
>
> get-qadcomputer -LdapFilter
> '(&(SamAccountName=start*)(SamAccountName=*end))'
>
> and hopefully that would return all computers matching "start*end"
> like:
> start123567end
> start123end
> etc.
> So...i can't even get the suffix alone to work...who can tell me what
> i'm doing wrong?
>
> Thanks!!
>

My System SpecsSystem Spec
Old 03-10-2008   #4 (permalink)
Ben Christian


 
 

Re: help with LDAP query

Amazing...Thanks!! =)

"Brandon Shell [MVP]" wrote:
Quote:

> Try this. Most computer sAMAccountName have $ at the end.
>
> get-qadcomputer -LdapFilter '(&(sAMAccountName=start*)(sAMAccountName=*end$))'
>
> Brandon Shell
> ---------------
> Blog: http://www.bsonposh.com/
> PSH Scripts Project: www.codeplex.com/psobject
>
> BC> I'm trying to do an LDAP query to find all machines ENDING with a
> BC> specific string. I have no problem finding machines with a prefix,
> BC> but i can't seem to get the suffix working right. Here's what I'm
> BC> trying...
> BC>
> BC> get-qadcomputer -LdapFilter '(SamAccountName=*end)'
> BC>
> BC> i actually want to get all pcs matching a beginning AND end...for
> BC> example
> BC>
> BC> get-qadcomputer -LdapFilter
> BC> '(&(SamAccountName=start*)(SamAccountName=*end))'
> BC>
> BC> and hopefully that would return all computers matching "start*end"
> BC> like:
> BC> start123567end
> BC> start123end
> BC> etc.
> BC> So...i can't even get the suffix alone to work...who can tell me
> BC> what i'm doing wrong?
> BC>
> BC> Thanks!!
> BC>
>
>
>
My System SpecsSystem Spec
Old 03-10-2008   #5 (permalink)
Ben Christian


 
 

Re: help with LDAP query

oh yeah...and i actually just combined the start and end...

i.e.
get-qadcomputer -Ldapfilter '(SamAccountName=start*end$)'



"Brandon Shell [MVP]" wrote:
Quote:

> Try this. Most computer sAMAccountName have $ at the end.
>
> get-qadcomputer -LdapFilter '(&(sAMAccountName=start*)(sAMAccountName=*end$))'
>
> Brandon Shell
> ---------------
> Blog: http://www.bsonposh.com/
> PSH Scripts Project: www.codeplex.com/psobject
>
> BC> I'm trying to do an LDAP query to find all machines ENDING with a
> BC> specific string. I have no problem finding machines with a prefix,
> BC> but i can't seem to get the suffix working right. Here's what I'm
> BC> trying...
> BC>
> BC> get-qadcomputer -LdapFilter '(SamAccountName=*end)'
> BC>
> BC> i actually want to get all pcs matching a beginning AND end...for
> BC> example
> BC>
> BC> get-qadcomputer -LdapFilter
> BC> '(&(SamAccountName=start*)(SamAccountName=*end))'
> BC>
> BC> and hopefully that would return all computers matching "start*end"
> BC> like:
> BC> start123567end
> BC> start123end
> BC> etc.
> BC> So...i can't even get the suffix alone to work...who can tell me
> BC> what i'm doing wrong?
> BC>
> BC> Thanks!!
> BC>
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
working LDAP query, well almost.. 800A000D VB Script
Query LDAP to get user Telephone VB Script
How can I query LDAP in WLM? Live Mail
LDAP Group Query Results Limitation VB Script
Not all users are retrieved in an LDAP query via ASP VB Script


Vista Forums 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 Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46