![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | working LDAP query, well almost.. 800A000D Hello all, The following script should get 2 properties form the Administrator user: "sAMAccountName" and "description". It does display the sAMAccountName but throws an error when it tries to display the user description. The code: Set objRootDSE = GetObject("LDAP://RootDSE") strDomainDN = objRootDSE.Get("DefaultNamingContext") Set objConn = CreateObject("ADODB.Connection") objConn.Provider = "ADsDSOObject" objConn.Open "Active Directory Provider" Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN & ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree") WScript.echo objRSUserDescr.Fields(0).Value WScript.echo objRSUserDescr.Fields(1).Value The error: this line: WScript.echo objRSUserDescr.Fields(1).Value Error: Type Mismatch Code: 800A000D I tried CStr(objRSUserDescr.Fields(1).Value), but get the same error. In my case, I cannot use GetObject("LDAP://" & UserDN) to get the user description. I have to query AD directly. Anyone an idea what goes wrong ? thanks in advance, Sander |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: working LDAP query, well almost.. 800A000D "Sander" <Sander@xxxxxx> wrote in message news:uqN2$YP8JHA.5424@xxxxxx Quote: > Hello all, > > The following script should get 2 properties form the Administrator user: > "sAMAccountName" and "description". > It does display the sAMAccountName but throws an error when it tries to > display the user description. > > The code: > Set objRootDSE = GetObject("LDAP://RootDSE") > strDomainDN = objRootDSE.Get("DefaultNamingContext") > Set objConn = CreateObject("ADODB.Connection") > objConn.Provider = "ADsDSOObject" > objConn.Open "Active Directory Provider" > > Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN & > ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree") > > WScript.echo objRSUserDescr.Fields(0).Value > WScript.echo objRSUserDescr.Fields(1).Value > > > The error: > this line: WScript.echo objRSUserDescr.Fields(1).Value > Error: Type Mismatch > Code: 800A000D WScript.echo Join(objRSUserDescr.Fields(1).Value, vbCrLf) |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: working LDAP query, well almost.. 800A000D You are right! How silly of me (I tried IsNull IsEmpty etc, but not IsArray ![]() It works like a charm! lots of Thanks! Sander "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:%23%23d1ydP8JHA.1376@xxxxxx Quote: > "Sander" <Sander@xxxxxx> wrote in message > news:uqN2$YP8JHA.5424@xxxxxx Quote: >> Hello all, >> >> The following script should get 2 properties form the Administrator user: >> "sAMAccountName" and "description". >> It does display the sAMAccountName but throws an error when it tries to >> display the user description. >> >> The code: >> Set objRootDSE = GetObject("LDAP://RootDSE") >> strDomainDN = objRootDSE.Get("DefaultNamingContext") >> Set objConn = CreateObject("ADODB.Connection") >> objConn.Provider = "ADsDSOObject" >> objConn.Open "Active Directory Provider" >> >> Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN & >> ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree") >> >> WScript.echo objRSUserDescr.Fields(0).Value >> WScript.echo objRSUserDescr.Fields(1).Value >> >> >> The error: >> this line: WScript.echo objRSUserDescr.Fields(1).Value >> Error: Type Mismatch >> Code: 800A000D > I believe this property is an array. Change your line to: > > WScript.echo Join(objRSUserDescr.Fields(1).Value, vbCrLf) > > > > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: working LDAP query, well almost.. 800A000D The description attribute is a strange one, because technically it is multi-valued, even though there is never more than one value. ADO retrieves it as an string array with one value, or a Null if there is no value assigned. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "Sander" <Sander@xxxxxx> wrote in message news:ucWBphP8JHA.3544@xxxxxx Quote: > You are right! > How silly of me (I tried IsNull IsEmpty etc, but not IsArray ![]() > > It works like a charm! > > lots of Thanks! > Sander > > > "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message > news:%23%23d1ydP8JHA.1376@xxxxxx Quote: >> "Sander" <Sander@xxxxxx> wrote in message >> news:uqN2$YP8JHA.5424@xxxxxx Quote: >>> Hello all, >>> >>> The following script should get 2 properties form the Administrator >>> user: "sAMAccountName" and "description". >>> It does display the sAMAccountName but throws an error when it tries to >>> display the user description. >>> >>> The code: >>> Set objRootDSE = GetObject("LDAP://RootDSE") >>> strDomainDN = objRootDSE.Get("DefaultNamingContext") >>> Set objConn = CreateObject("ADODB.Connection") >>> objConn.Provider = "ADsDSOObject" >>> objConn.Open "Active Directory Provider" >>> >>> Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN & >>> ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree") >>> >>> WScript.echo objRSUserDescr.Fields(0).Value >>> WScript.echo objRSUserDescr.Fields(1).Value >>> >>> >>> The error: >>> this line: WScript.echo objRSUserDescr.Fields(1).Value >>> Error: Type Mismatch >>> Code: 800A000D >> I believe this property is an array. Change your line to: >> >> WScript.echo Join(objRSUserDescr.Fields(1).Value, vbCrLf) >> >> >> >> |
My System Specs![]() |
| | #5 (permalink) |
| Guest | Re: working LDAP query, well almost.. 800A000D "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:ee8CVqP8JHA.5400@xxxxxx Quote: > The description attribute is a strange one, because technically it is > multi-valued, even though there is never more than one value. ADO > retrieves it as an string array with one value, or a Null if there is no > value assigned. using the Join method to prevent an exception in the event that it is empty. sDescription = objRSUserDescr.Fields("description").Value If IsArray(sDescription) Then sDescription = Join(sDescription, Empty) Else sDescription = Empty End If WScript.Echo sDescription |
My System Specs![]() |
| | #6 (permalink) |
| Guest | Re: working LDAP query, well almost.. 800A000D "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:%23ba8eAQ8JHA.1336@xxxxxx Quote: > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in > message news:ee8CVqP8JHA.5400@xxxxxx Quote: >> The description attribute is a strange one, because technically it is >> multi-valued, even though there is never more than one value. ADO >> retrieves it as an string array with one value, or a Null if there is no >> value assigned. > Sander, to Richard's point, you should probably do an IsArray test before > using the Join method to prevent an exception in the event that it is > empty. > > sDescription = objRSUserDescr.Fields("description").Value > > If IsArray(sDescription) Then > sDescription = Join(sDescription, Empty) > Else > sDescription = Empty > End If > > WScript.Echo sDescription > value is an array. I use code similar to: ==== If IsNull(sDescription) Then sDescription = "" Else For Each sItem In sDescription sDescription = sItem Next End If ====== The Join function actually looks cleaner than the For Each loop I use. I generally the the For Each loop when I deal with other multi-valued attributes, but in this case the Join is better. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #7 (permalink) |
| Guest | Re: working LDAP query, well almost.. 800A000D When in doubt, have VBScript tell you about the variable. Functions Typename and/or Vartype would have given you the array clue. -Paul Randall "Sander" <Sander@xxxxxx> wrote in message news:ucWBphP8JHA.3544@xxxxxx Quote: > You are right! > How silly of me (I tried IsNull IsEmpty etc, but not IsArray ![]() > > It works like a charm! > > lots of Thanks! > Sander > > > "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message > news:%23%23d1ydP8JHA.1376@xxxxxx Quote: >> "Sander" <Sander@xxxxxx> wrote in message >> news:uqN2$YP8JHA.5424@xxxxxx Quote: >>> Hello all, >>> >>> The following script should get 2 properties form the Administrator >>> user: "sAMAccountName" and "description". >>> It does display the sAMAccountName but throws an error when it tries to >>> display the user description. >>> >>> The code: >>> Set objRootDSE = GetObject("LDAP://RootDSE") >>> strDomainDN = objRootDSE.Get("DefaultNamingContext") >>> Set objConn = CreateObject("ADODB.Connection") >>> objConn.Provider = "ADsDSOObject" >>> objConn.Open "Active Directory Provider" >>> >>> Set objRSUserDescr = objConn.Execute("<LDAP://" & strDomainDN & >>> ">;(&(objectClass=user)(sAMAccountName=Administrator));sAMAccountName,description;subtree") >>> >>> WScript.echo objRSUserDescr.Fields(0).Value >>> WScript.echo objRSUserDescr.Fields(1).Value >>> >>> >>> The error: >>> this line: WScript.echo objRSUserDescr.Fields(1).Value >>> Error: Type Mismatch >>> Code: 800A000D >> I believe this property is an array. Change your line to: >> >> WScript.echo Join(objRSUserDescr.Fields(1).Value, vbCrLf) >> >> >> >> |
My System Specs![]() |
| | #8 (permalink) |
| Guest | Re: working LDAP query, well almost.. 800A000D Thats exactly what i did ;] Thanks again James & Richard! "James Whitlow" <jwhitlow.60372693@xxxxxx> wrote in message news:%23ba8eAQ8JHA.1336@xxxxxx Quote: > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in > message news:ee8CVqP8JHA.5400@xxxxxx Quote: >> The description attribute is a strange one, because technically it is >> multi-valued, even though there is never more than one value. ADO >> retrieves it as an string array with one value, or a Null if there is no >> value assigned. > Sander, to Richard's point, you should probably do an IsArray test before > using the Join method to prevent an exception in the event that it is > empty. > > sDescription = objRSUserDescr.Fields("description").Value > > If IsArray(sDescription) Then > sDescription = Join(sDescription, Empty) > Else > sDescription = Empty > End If > > WScript.Echo sDescription > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Query LDAP to get user Telephone | VB Script | |||
| How can I query LDAP in WLM? | Live Mail | |||
| Why isn't this LDAP query working on the other domain in the fores | VB Script | |||
| Not all users are retrieved in an LDAP query via ASP | VB Script | |||
| help with LDAP query | PowerShell | |||