Home All Groups Group Topic Archive Search About

LDAP query fails... because of parentheses?

Author
24 Feb 2009 4:45 PM
Highlander
(watch for word wrap below)

Hello all.

I'm using the script found here:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/hey0419.mspx

When I run it, as it cycles through all the members of the Group, if
the "strUser" variable is something like this:
CN=Smith\, John,CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com

....there's no problem.

But when the "strUser" variable is this:
CN=Doe\, Jane (LIFE U/W),CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com

Then the script blows up, on this line:
Set objMember = GetObject("LDAP://" & strUser)

With this error message:
(null): 0x80005000

The obvious difference is that the strUser variable in question
contains parentheses. Anyone know a fix for this?

Any help would be greatly appreciated. Thanks!

- Dave

Author
24 Feb 2009 4:59 PM
Richard Mueller [MVP]
Show quote Hide quote
"Highlander" <tron9***@msn.com> wrote in message
news:043c069b-cc9c-45df-b7bd-f1fb2ef91626@z1g2000yqn.googlegroups.com...
> (watch for word wrap below)
>
> Hello all.
>
> I'm using the script found here:
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/hey0419.mspx
>
> When I run it, as it cycles through all the members of the Group, if
> the "strUser" variable is something like this:
> CN=Smith\, John,CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>
> ...there's no problem.
>
> But when the "strUser" variable is this:
> CN=Doe\, Jane (LIFE U/W),CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>
> Then the script blows up, on this line:
> Set objMember = GetObject("LDAP://" & strUser)
>
> With this error message:
> (null): 0x80005000
>
> The obvious difference is that the strUser variable in question
> contains parentheses. Anyone know a fix for this?
>
> Any help would be greatly appreciated. Thanks!
>
> - Dave

I believe the problem is actually the forward slash. AD does not require
that this be escaped, but ADSI does. Both open and close parantheses are
fine. Escape the forward slash with the backslash escape character, just as
you escape the comma. For example:

CN=Doe\, Jane (LIFE U\/W),CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com

If you are retrieving the DN from some IADs method, all characters that need
to be escaped, will be escaped, except for the forward slash. In my programs
I use code similar to:

strUserDN = Replace(strUserDN, "/", "\/")

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Are all your drivers up to date? click for free checkup

Author
24 Feb 2009 5:12 PM
Richard Mueller [MVP]
Show quote Hide quote
"Richard Mueller [MVP]" <rlmueller-nospam@ameritech.nospam.net> wrote in
message news:uMLJLFqlJHA.3760@TK2MSFTNGP03.phx.gbl...
>
> "Highlander" <tron9***@msn.com> wrote in message
> news:043c069b-cc9c-45df-b7bd-f1fb2ef91626@z1g2000yqn.googlegroups.com...
>> (watch for word wrap below)
>>
>> Hello all.
>>
>> I'm using the script found here:
>> http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/hey0419.mspx
>>
>> When I run it, as it cycles through all the members of the Group, if
>> the "strUser" variable is something like this:
>> CN=Smith\, John,CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>>
>> ...there's no problem.
>>
>> But when the "strUser" variable is this:
>> CN=Doe\, Jane (LIFE U/W),CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>>
>> Then the script blows up, on this line:
>> Set objMember = GetObject("LDAP://" & strUser)
>>
>> With this error message:
>> (null): 0x80005000
>>
>> The obvious difference is that the strUser variable in question
>> contains parentheses. Anyone know a fix for this?
>>
>> Any help would be greatly appreciated. Thanks!
>>
>> - Dave
>
> I believe the problem is actually the forward slash. AD does not require
> that this be escaped, but ADSI does. Both open and close parantheses are
> fine. Escape the forward slash with the backslash escape character, just
> as you escape the comma. For example:
>
> CN=Doe\, Jane (LIFE U\/W),CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>
> If you are retrieving the DN from some IADs method, all characters that
> need to be escaped, will be escaped, except for the forward slash. In my
> programs I use code similar to:
>
> strUserDN = Replace(strUserDN, "/", "\/")
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>


From the link you provided, replace this:

For Each strUser on objGroup.Member
    Set objMember = GetObject("LDAP://" & strUser)
    Wscript.Echo objMember.CN & ", " & objMember.Class
Next

with this:

For Each strUser on objGroup.Member
    Set objMember = GetObject("LDAP://" & Replace(strUser, "/", "\/"))
    Wscript.Echo objMember.CN & ", " & objMember.Class
Next

Interestingly, you can use the Members method to retrieve a collect of
object references to the members of the group. This method works even when
the DN of a member has the "/" character. For example:

For Each objMember In objGroup.Members
    Wscript. objMember.cn & ", " & objMember.Class
Next

I would actually prefer this method. The Members method of IADsGroup
interface is able to bind to the member objects, I assume because it does
not use ADSI (or perhaps someone coded the method to handle this situation).

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
Author
24 Feb 2009 5:24 PM
HL0105
On Feb 24, 11:12 am, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
Show quoteHide quote
> "Richard Mueller [MVP]" <rlmueller-nos...@ameritech.nospam.net> wrote in
> messagenews:uMLJLFqlJHA.3***@TK2MSFTNGP03.phx.gbl...
>
>
>
>
>
>
>
> > "Highlander" <tron9***@msn.com> wrote in message
> >news:043c069b-cc9c-45df-b7bd-f1fb2ef91626@z1g2000yqn.googlegroups.com...
> >> (watch for word wrap below)
>
> >> Hello all.
>
> >> I'm using the script found here:
> >>http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/h....
>
> >> When I run it, as it cycles through all the members of the Group, if
> >> the "strUser" variable is something like this:
> >> CN=Smith\, John,CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>
> >> ...there's no problem.
>
> >> But when the "strUser" variable is this:
> >> CN=Doe\, Jane (LIFE U/W),CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>
> >> Then the script blows up, on this line:
> >> Set objMember = GetObject("LDAP://" & strUser)
>
> >> With this error message:
> >> (null): 0x80005000
>
> >> The obvious difference is that the strUser variable in question
> >> contains parentheses. Anyone know a fix for this?
>
> >> Any help would be greatly appreciated. Thanks!
>
> >> - Dave
>
> > I believe the problem is actually the forward slash. AD does not require
> > that this be escaped, but ADSI does. Both open and close parantheses are
> > fine. Escape the forward slash with the backslash escape character, just
> > as you escape the comma. For example:
>
> > CN=Doe\, Jane (LIFE U\/W),CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>
> > If you are retrieving the DN from some IADs method, all characters that
> > need to be escaped, will be escaped, except for the forward slash. In my
> > programs I use code similar to:
>
> > strUserDN = Replace(strUserDN, "/", "\/")
>
> > --
> > Richard Mueller
> > MVP Directory Services
> > Hilltop Lab -http://www.rlmueller.net
> > --
>
> From the link you provided, replace this:
>
> For Each strUser on objGroup.Member
>     Set objMember = GetObject("LDAP://" & strUser)
>     Wscript.Echo objMember.CN & ", " & objMember.Class
> Next
>
> with this:
>
> For Each strUser on objGroup.Member
>     Set objMember = GetObject("LDAP://" & Replace(strUser, "/", "\/"))
>     Wscript.Echo objMember.CN & ", " & objMember.Class
> Next
>
> Interestingly, you can use the Members method to retrieve a collect of
> object references to the members of the group. This method works even when
> the DN of a member has the "/" character. For example:
>
> For Each objMember In objGroup.Members
>     Wscript. objMember.cn & ", " & objMember.Class
> Next
>
> I would actually prefer this method. The Members method of IADsGroup
> interface is able to bind to the member objects, I assume because it does
> not use ADSI (or perhaps someone coded the method to handle this situation).
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab -http://www.rlmueller.net
> --- Hide quoted text -
>
> - Show quoted text -

Damn you're good! Your replace command to escape the forward slash
worked like a champ. For that, and for the additional info, thanks
Richard!

Happy Fat Tuesday!

- Dave
Author
2 Mar 2009 12:04 AM
Abel Martinez
Show quote Hide quote
"Highlander" <tron9***@msn.com> wrote in message
news:043c069b-cc9c-45df-b7bd-f1fb2ef91626@z1g2000yqn.googlegroups.com...
> (watch for word wrap below)
>
> Hello all.
>
> I'm using the script found here:
> http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/hey0419.mspx
>
> When I run it, as it cycles through all the members of the Group, if
> the "strUser" variable is something like this:
> CN=Smith\, John,CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>
> ...there's no problem.
>
> But when the "strUser" variable is this:
> CN=Doe\, Jane (LIFE U/W),CN=Users,DC=Name1,DC=ad,DC=Name2,DC=com
>
> Then the script blows up, on this line:
> Set objMember = GetObject("LDAP://" & strUser)
>
> With this error message:
> (null): 0x80005000
>
> The obvious difference is that the strUser variable in question
> contains parentheses. Anyone know a fix for this?
>
> Any help would be greatly appreciated. Thanks!
>
> - Dave

Bookmark and Share

Post Thread options