Results 1 to 3 of 3

Thread: How to modify the proxyAdress property in AD with VBScript

  1. #1
    Raskil2000 Guest

    How to modify the proxyAdress property in AD with VBScript

    Hi,

    I need to change the default proxyAdress for all AD Users with VBScript.
    I've found out that the E-Mail addresses used for exchange is stored in the
    proxyAdress property array including an smtp prefix. The default address is
    distinguished by letter case. The default address includes the prefix in
    upper case.
    So here are my questions:

    1. How do i modify a property inside the array with vbscript. I can modify
    propertys which are strings, but i never tied it with those array propertys.
    2. If i set another prefix in upper case will the old default address be
    automatically convertet to lower case?

    Thx in advance,

    Benjamin Fischer

  2. #2
    Richard Mueller [MVP] Guest

    Re: How to modify the proxyAdress property in AD with VBScript

    Benjamin Fischer wrote:

    > I need to change the default proxyAdress for all AD Users with VBScript.
    > I've found out that the E-Mail addresses used for exchange is stored in
    > the
    > proxyAdress property array including an smtp prefix. The default address
    > is
    > distinguished by letter case. The default address includes the prefix in
    > upper case.
    > So here are my questions:
    >
    > 1. How do i modify a property inside the array with vbscript. I can modify
    > propertys which are strings, but i never tied it with those array
    > propertys.
    > 2. If i set another prefix in upper case will the old default address be
    > automatically convertet to lower case?


    Use the PutEx method of the user object to modify multi-valued attributes,
    such as otherTelephone or proxyAddresses. For example, to add another phone
    number to otherTelephone:

    Const ADS_PROPERTY_APPEND = 3
    Set objUser = GetObject("LDAP://cn=Jim Smith,ou=Sales,dc=MyDomain,dc=com")
    objUser.PutEx ADS_PROPERTY_APPEND, "otherTelephone", Array("425-555-0116")
    objUser.SetInfo

    or, to modify (replace) the attribute value:

    Const ADS_PROPERTY_UPDATE = 2
    objUser.PutEx ADS_PROPERTY_UPDATE, "otherTelephone", Array("425-555-0116",
    "425-555-1234")

    To read a multi-valued attribute into an array use the GetEx method:

    colNumbers = objUser.GetEx("otherTelephone")

    If you need to modify an existing entry, you need to read the attribute into
    an array, enumerate the array to find the old value, modify it, then update
    the attribute with the new array. Perhaps:
    ============
    Option Explicit

    Dim strOldAddress, strNewAddress, blnFound, blnSkip
    Dim objUser, colAddresses, k

    Const ADS_PROPERTY_UPDATE = 2
    Const ADS_PROPERTY_APPEND = 3
    strOldAddress = "[email protected]"
    strNewAddress = "[email protected]"
    Set objUser = GetObject("LDAP://cn=Jim Smith,ou=Sales,dc=MyDomain,dc=com")
    colAddresses = objUser.GetEx("proxyAddresses")
    blnFound = False
    blnSkip = False
    For k = 0 To UBound(colAddresses)
    If (colAddresses(k) = strNewAddress) Then
    blnSkip = True
    End If
    If (colAddresses(k) = strOldAddress) Then
    colAddresses(k) = strNewAddress
    blnFound = True
    End If
    Next
    If (blnSkip = False) Then
    If (blnFound = True) Then
    objUser.PutEx ADS_PROPERTY_UPDATE, "proxyAddresses", colAddresses
    Else
    objUser.PutEx ADS_PROPERTY_APPEND, "proxyAddresses",
    Array(strNewAddress)
    End If
    objUser.SetInfo
    End If
    ===========
    The logic depends on when you want to add the new entry or modify an
    existing. You should take into account that the old entry may not be there
    and the new one may already be there. Also, note that attributes values are
    case aware but not case sensitive.

    --
    Richard Mueller
    Microsoft MVP Scripting and ADSI
    Hilltop Lab - http://www.rlmueller.net
    --



  3. #3
    Richard Mueller [MVP] Guest

    Re: How to modify the proxyAdress property in AD with VBScript

    In the code I posted earlier, if the user has no value assigned to the
    multi-value attribute, the GetEx method will raise an error. This error can
    be trapped. Perhaps:
    ===========
    Set objUser = GetObject("LDAP://cn=Jim Smith,ou=Sales,dc=MyDomain,dc=com")
    On Error Resume Next
    colAddresses = objUser.GetEx("proxyAddresses")
    If (Err.Number <> 0) Then
    On Error GoTo 0
    objUser.PutEx ADS_PROPERTY_APPEND, "proxyAddresses",
    Array(strNewAddress)
    Wscript.Quit
    End If
    On error GoTo 0
    ==========
    To do this for all users in an OU, bind to the OU, filter on objects of
    class "user", and enumerate the users in a loop. Code similar to what I
    posted would be in the loop.

    Or, you can use ADO to retrieve distinguishedName and proxyAddresses for all
    users. See this link for details on using ADO to rerieve attribute values
    from AD:

    http://www.rlmueller.net/ADOSearchTips.htm

    ADO cannot be used to modify values, so you will need to bind to the user
    objects (with distinguishedName). Also, ADO retrieves multi-valued attribute
    values as arrays, but returns Null if there is no value assigned. You can
    check with the IsNull function. If IsNull, use ADS_PROPERTY_APPEND to assign
    the new value as a array. Otherwise loop through the array to check for the
    old and new values. Again, the exact logic depends on what you want to
    accomplish.

    --
    Richard Mueller
    Microsoft MVP Scripting and ADSI
    Hilltop Lab - http://www.rlmueller.net
    --



Similar Threads

  1. File unblock property
    By Patton in forum Windows Security
    Replies: 1
    Last Post: 25-10-2012, 05:11 PM
  2. What is a Java property category?
    By Viensterrr in forum Software Development
    Replies: 4
    Last Post: 22-01-2010, 10:41 PM
  3. SelectionObject property
    By rooki in forum Software Development
    Replies: 3
    Last Post: 30-11-2009, 10:05 PM
  4. CSS Property For IMG
    By Joko in forum Software Development
    Replies: 3
    Last Post: 12-08-2009, 11:20 AM
  5. how to read inheritance property of folder in vbscript
    By vivekmohan in forum Software Development
    Replies: 3
    Last Post: 29-07-2009, 05:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,788,789.36359 seconds with 16 queries