Hey, Scripting Guy! How can I add an email address to the proxyAddresses attribute without overwriting all the existing attributes?
— DH
Hey, DH. For those of you who aren’t too familiar with the proxyAddresses attribute (and, alas, that includes the Scripting Guys) proxyAddresses is an attribute added to Active Directory by Microsoft Exchange; it’s simply an alias by which an Exchange user can be recognized by a non-Exchange mail system. If you echo back the proxy addresses for a given user you’re likely to see something similar to this:
NUMERIC:4257050743 sip:kenmyer@fabrikam.com X500:/o=fabrikam/ou=APPS-WGA/cn=Xenix_Users/cn=kenmyer X500:/o=fabrikam/ou=First Administrative Group/cn=Recipients/cn=kenmyer x400:c=US;a=MCI;p=fab;o=northamerica;s=Myer;g=Ken; X500:/O=fabrikam/OU=northamerica/cn=Recipients/cn=kenmyer X400:c=US;a=finance;p=fabrikam;o=fabrikam;s=Myer;g=Ken; x500:/o=fabrikam/ou=northamerica/cn=Recipients/cn=556899 smtp:kenmyer@fabrikam.com SMTP:kenmyer@finance.fabrikam.com
If you’re thinking, “Wow, that’s s lot of stuff for one little attribute to have,” well, that’s because proxyAddresses happens to be a multi-valued attribute, an attribute that can contain more than one value. And that’s why this particular question is so tricky. Suppose we wanted to add a new proxy address – kenmyer@northamerica.fabrikam.com – to the list of proxyAddresses. We don’t want to delete the existing addresses; we just want to add an additional one.
Hey, no problem; after all, everyone knows how to modify an Active Directory attribute, right? And so you try a script similar to this:
Set objUser = GetObject _ (“LDAP://atl-dc-1/CN=Ken Myer,OU=Finance,DC=fabrikam,DC=com”) objUser.proxyAddresses = kenmyer@northamerica.fabrikam.com objUser.SetInfo
And guess what you get back the next time you echo Ken Myer’s proxy addresses:
kenmyer@northamerica.fabrikam.com
Uh-oh: we deleted all the old proxy addresses and replaced them with the new address. Not what we wanted to do at all.
So how can we simply tack an additional value onto the end of a multi-valued attribute? Why, we just need to use the PutEx method:
Const ADS_PROPERTY_APPEND = 3Set objUser = GetObject _ (“LDAP://cn=KenMyer,ou=Finance,dc=fabrikam,dc=com”)
objUser.PutEx ADS_PROPERTY_APPEND, “proxyAddresses”, _ Array(“kenmyer@northamerica.fabrikam.com “)
PutEx is an ADSI method designed for working with multi-valued attributes; in fact, PutEx offers four different options for working with multi-valued attributes:
Constant |
Value |
Description |
ADS_PROPERTY_CLEAR |
1 |
Clears the value (or values) from the specified attribute. |
ADS_PROPERTY_UPDATE |
2 |
Replaces the value in the specified attribute with new values. |
ADS_PROPERTY_APPEND |
3 |
Appends a new value (or values) to the specified attribute. |
ADS_PROPERTY_DELETE |
4 |
Deletes the value (or values) from the specified attribute. |
We won’t spend a lot of time detailing how PutEx works; for more information you might check out the Modifying Multivalued Attributes section in the Microsoft Windows 2000 Scripting Guide.
Now, back to our script. We want to append a new value to proxyAddresses; consequently in the first line of the script we define a constant named ADS_PROPERTY_APPEND and set the value to 3:
Const ADS_PROPERTY_APPEND = 3
We bind to the Ken Myer user account and then call the PutEx method, passing three parameters:
• |
The constant ADS_PROPERTY_APPEND, which tells the script to append the new value to any existing values. |
• |
The name of the attribute we want to work with (proxyAddresses). |
• |
The value we want to append (in other words, the new proxy address). |
Note that even though we’re adding only a single value we need to pass that value as an array; hence our actual code looks like this:
objUser.PutEx ADS_PROPERTY_APPEND, “proxyAddresses”, _ Array(“kenmyer@northamerica.fabrikam.com”)
And what do we get when we echo the proxy addresses for Ken Myer:
kenmyer@northamerica.fabrikam.com NUMERIC:4257050743 sip:kenmyer@fabrikam.com X500:/o=fabrikam/ou=APPS-WGA/cn=Xenix_Users/cn=kenmyer X500:/o=fabrikam/ou=First Administrative Group/cn=Recipients/cn=kenmyer x400:c=US;a=MCI;p=fab;o=northamerica;s=Myer;g=Ken; X500:/O=fabrikam/OU=northamerica/cn=Recipients/cn=kenmyer X400:c=US;a=finance;p=fabrikam;o=fabrikam;s=Myer;g=Ken; x500:/o=fabrikam/ou=northamerica/cn=Recipients/cn=556899 smtp:kenmyer@fabrikam.com SMTP:kenmyer@finance.fabrikam.com
Cool, huh?
Incidentally, there’s no guarantee that the new proxy address will show up first in the list of addresses; when it comes to multi-valued attributes the order of the individual attributes is not guaranteed. But that doesn’t matter just as long as kenmyer@northamerica.fabrikam.com shows up somewhere in the list.
0 comments