Multi-valued strings

Discussion in 'Scripting' started by Mel K, Aug 28, 2008.

  1. Mel K

    Mel K Guest

    Hello:



    How can I get the first value of a multi-valued string in VBS? I'm trying to
    get the first (and only) entry in the canonicalName property of an AD user
    object. I'm trying to do something like this:



    strSomeString = objADUser.canonicalName



    Thanks.
     
    Mel K, Aug 28, 2008
    #1
    1. Advertisements

  2. You treat multi-valued attributes similar to arrays. However, an additional
    factor is that canonicalName is constructed (also called operational). You
    must use the GetInfoEx method to retrieve the values, then the GetEx method
    to enumerate them. For example:
    ====
    Set objUser = GetObject("LDAP://cn=Jim Smith,ou=West,dc=MyDomain,dc=com")

    objUser.GetInfoEx Array("canonicalName"), 0

    For Each strValue in objUser.GetEx("canonicalName")
    Wscript.Echo strValue
    Next
    ========
    Note that there is no order to the values in a multi-valued attribute, so
    you cannot say which is the first. Also, the above would raise an error on
    the GetEx method if the array had no values. The code assumes that all user
    objects have at least one value.
     
    Richard Mueller [MVP], Aug 28, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.