Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to modify the proxyAdress property in AD with VBScript

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 17-07-2007
Raskil2000
 
Posts: n/a
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

Reply With Quote
  #2  
Old 17-07-2007
Richard Mueller [MVP]
 
Posts: n/a
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 = "FirstLast@MyCompany.com"
strNewAddress = "FirstLast@NewCompany.com"
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
--


Reply With Quote
  #3  
Old 17-07-2007
Richard Mueller [MVP]
 
Posts: n/a
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
--


Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to modify the proxyAdress property in AD with VBScript"
Thread Thread Starter Forum Replies Last Post
File unblock property Patton Windows Security 1 25-10-2012 05:11 PM
What is a Java property category? Viensterrr Software Development 4 22-01-2010 10:41 PM
SelectionObject property rooki Software Development 3 30-11-2009 10:05 PM
CSS Property For IMG Joko Software Development 3 12-08-2009 11:20 AM
how to read inheritance property of folder in vbscript vivekmohan Software Development 3 29-07-2009 05:30 PM


All times are GMT +5.5. The time now is 04:35 PM.