Login | |
|
 |
Replace the Primary mail address in AD - 6/24/2007 5:25:03 AM
|
|
 |
|
| |
stubar
Posts: 53
Score: 0
Joined: 7/14/2005
Status: offline
|
Hello Having a bit of trouble here. What I want to do is replace the Primary mail address, the objUser.mail, with a second address. Currently I have tried many permutations around the script below. The core of it comes from MS which was to put a secondary, or proxy, address in. This works nicely no complaints. But then I want to take that secondary address and make it a primary whilst relegating the previous address to secondary. (Make sense?). However, I can successfully get half of it to work but it's not correct. The new primary shows up in the general tab as the mail address and in the GAL but in the E-Mail Addresses tab the old primary is still there as the primary. As I say I have tried many permutations and get a variety of results but not the one I want. I have scoured Google and various forums using a different seach keywords but I'm not having a lot of luck. Please help ' Set up the connections '---------------------------------------------------------------- Const ADS_PROPERTY_UPDATE = 2 Const ADS_PROPERTY_APPEND = 3 dim mail, newmail newmail = ("first.surname.cllr@domain.org.uk") Set objUser = GetObject _ ("LDAP://serv/cn=first surname,ou=Test,ou=Service,dc=domain,dc=org,dc=uk") ' Capture the elements '---------------------------------------------------------------- currmail = objUser.mail wscript.echo("This is the current mail address " & currmail) ' *** New proxy email address objUser.PutEx ADS_PROPERTY_APPEND, "proxyAddresses", _ Array("smtp:" & newmail) wscript.echo("This is the new proxy mail address " & newmail) objUser.SetInfo ' *** New primary email address objUser.PutEx ADS_PROPERTY_UPDATE, "mail", _ Array("SMTP:" & newmail) wscript.echo("This is the new Primary mail address " & newmail) objUser.SetInfo ' *** New proxy email address objUser.PutEx ADS_PROPERTY_APPEND, "proxyAddresses", _ Array("smtp:" & currmail) wscript.echo("This is the new proxy mail address " & currmail) objUser.SetInfo ' *** Turn off recipient policy updates objUser.Put "msexchpoliciesexcluded", "{26491CFC-9E50-4857-861B-0CB8DF22B5D7}" objUser.SetInfo wscript.echo("Complete")
|
|
| |
|
|
|
 |
RE: Replace the Primary mail address in AD - 6/24/2007 2:43:21 PM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
Not sure why you care about the 'mail' field, but all you have to do to set someone's "Primary" email address (the one that is used when they send an email) is to modify the proxyAddresses field. Whichever one of those addresses starts with SMTP instead of smtp is the Primary. Secondary addresses all start with a lower-case smtp, but primaries start with upper-case SMTP. Other than that, the mail field is just for display purposes.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: Replace the Primary mail address in AD - 6/24/2007 8:40:08 PM
|
|
 |
|
| |
4scriptmoni
Posts: 208
Score: 0
Joined: 5/3/2007
Status: offline
|
maybe if you first set both email address to "" and then first set SMTP then smtp...
_____________________________
Enterprise Microsoft Scripts Exchange, Login/Logout Monitor,TS, Monitoring, Security, AD, etc... http://www.felipeferreira.net
|
|
| |
|
|
|
 |
RE: Replace the Primary mail address in AD - 6/25/2007 12:57:33 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
you are *appending* the proxyaddresses field with the new data. If you instead, replace teh data witht he new data, you'd be fine. I have to do this once in a while with my clients' addresses, for example, when they want to change their email addresses, or something. if you use the below format, you'd be ok. .PutEx 4, "ProxyAddresses", Array
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: Replace the Primary mail address in AD - 6/25/2007 6:56:42 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1194
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
Think of it this way: the .mail and .proxyAddresses are two different fields. .mail is a string field .proxyAddresses is an array field Look at this: a1 = array(1,2,3) a1 = array(4,5,6) in the second line, I overwrote what I had in the array from the first line. This is what you need to do with the proxyAddresses field. OVERWRITE anything that you already have in it with the new data. For the .mail field, put the SMTp address in there. Am rushed for time right now, but will hack out a script that will do what I am talking about for you this afternoon.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
|
|