Re: How to modify the proxyAdress property in AD with VBScript
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 17 Jul 2007 12:39:31 -0500
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 = "FirstLast@xxxxxxxxxxxxx"
strNewAddress = "FirstLast@xxxxxxxxxxxxxx"
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
--
.
- Follow-Ups:
- Re: How to modify the proxyAdress property in AD with VBScript
- From: Richard Mueller [MVP]
- Re: How to modify the proxyAdress property in AD with VBScript
- Prev by Date: Re: VB Script for creating Environment Variable
- Next by Date: Re: How to modify the proxyAdress property in AD with VBScript
- Previous by thread: Re: CACLS failing on syntaxt - halfway through
- Next by thread: Re: How to modify the proxyAdress property in AD with VBScript
- Index(es):
Relevant Pages
|