SET primary SMTP
Hello, I use Exchange 2007 and I got a list of SamAccountName users in a txt file. I would like from that list to deactivate the Email address policy and set a custom PrimarySmtpAddress for each of them. So my txt file looks like: GRAIG USER USER2 And I would know how to deactivate the Email address policy but Waht I really do Not know is how to set up a custom email address: I would like to set: GRAIG,graig.lastname@company.com USER, user.lastname@company.com USER2,user2.lastname@company.com Would you haev any idea how I could set it up? I do have the list of user and the email address per user. Thanks in advance if you can be of any help!! Graig
November 17th, 2010 9:28am

The easiest way would be to get your list in the form of a .csv with column headings, like this. You can do it up in Excel, and then save it as type .csv. User,Address GRAIG,graig.lastname@company.com USER, user.lastname@company.com USER2,user2.lastname@company.com then save that as e.g. c:\somedir\addrlist.csv Then: import-csv c:\somedir\addrlist.csv | foreach-object {set-mailbox $_.User -primarysmtpaddress $_.address}[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 17th, 2010 9:50am

Here is an example of changing the current primary SMTP address to a secondary and creating a new primary. I wrote this vbscript ages ago, but it still works and provides a good example of modifying the appropriate user properties in Active Directory. . I guess I should probably update the script to PowerShell :-) First, the proxyaddresses attribute contains a flat list of all the addresses. What make an SMTP address in ProxyAddresses the Primary SMTP address is placing it in the "mail" property as well. To keep the addresses from being updated by the address policy, you need to add a specific GUID, "{26491CFC-9E50-4857-861B-0CB8DF22B5D7}", to the msexchpoliciesexcluded property. John 'Quick and dirty script to remove the default primary smtp address,set a new, and put the old one back as a ' secondary for each member of a nested group ' Author - John Fullbright ' Creation date - 2/12/2004 ' ' ' --------------------------------------------- SCRIPT CONFIGURATION -------------------------------------------------- ' ' ' strGroupDN is the DN of the group you wish to apply the changes to. You can copy and paste the DN from ADSIEDIT ' strDefaultSuffix is the suffix suffix stamped by the recipient policy for the domain the group is in ' strNewSuffix is the custom suffix you wish to replace the default suffix with for strGroupDN ' ' If you need anything more complex than mailnickname as the prefix then you must modify the script ' ' You will need to create a recipient policy for strNewSuffix with a blank filter so Exchange will accept for delivery ' strGroupDN = "CN=Test Group,OU=Information Technology,OU=Users,OU=Corporate Office,DC=child,DC=mycompany,DC=com" strDefaultSuffix = "@permutation1.com" strNewSuffix = "@permutation2.com" ' ' ' ----------------------------------------------- END CONFIGURATION --------------------------------------------------- ' ' ' create the dictionary and start stamping set dicSeenGroupMember = CreateObject("Scripting.Dictionary") StampMembers "LDAP://" & strGroupDN, dicSeenGroupMember ' Function StampMembers (strGroupADsPath, dicSeenGroupMember) ' set objGroup = GetObject(strGroupADsPath) ' for each objMember In objGroup.Members ' ' if the member is a user then stamp it if objMember.Class = "user" then ' If the smtp address was already there as a secondary smtp address then delete it objMember.PutEx 4, "ProxyAddresses", Array("smtp:" & objMember.mailnickname & strNewSuffix) objMember.SetInfo ' put the smtp address in as a primary then set mail and msexchpoliciesexcluded objMember.PutEx 3, "ProxyAddresses", Array("SMTP:" & objMember.mailnickname & strNewSuffix) objMember.Put "mail", objMember.mailnickname & strNewSuffix objMember.Put "msexchpoliciesexcluded", "{26491CFC-9E50-4857-861B-0CB8DF22B5D7}" objMember.SetInfo ' delete the old primary objMember.PutEx 4, "ProxyAddresses", Array("SMTP:" & objMember.mailnickname & strDefaultSuffix) objMember.SetInfo ' add the old primary back as a secondary objMember.PutEx 3, "ProxyAddresses", Array("smtp:" & objMember.mailnickname & strDefaultSuffix) objMember.setinfo end if ' ' if it is a group then expand the group recursively if objMember.Class = "group" then ' if dicSeenGroupMember.Exists(objMember.ADsPath) then ' do nothing to avoid looping if we already stamped it else ' add it to the dictionary and stamp it dicSeenGroupMember.Add objMember.ADsPath, 1 StampMembers objMember.ADsPath, dicSeenGroupMember end if ' end if ' next ' End Function
November 17th, 2010 10:50pm

Go to Organization Configuration -> Hub Transport -> Email Address Policies Ther create a new policy and include all the recipients. Click next. Select conditions, if you don't have it, just click preview and look on the mailboxes to which policy will apply. If they are ok click next. Then click "Add" button and select "Email address port" and there check a "Firstname.lastname" button. Then select accepted domain from the list and apply policy to your users. The default policy will not work if there is any other policy created. Is that what you wanted to do?
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 3:05am

Thanks Mjolinor, when I valide the commang, I got no error but no changes neither even with a start edge synch. Have I missed something?
November 18th, 2010 3:27am

Were the original primary addresses created by an email address policy, and is it still enabled for those users? If so, it's going to change them back. [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 5:51am

I guess those accounts were created by an email policy.. So What should I do? I did remove the email address policy and ran you command but I had no change applied afterwards. I have some mailusers: Should I deactivate and reactivte them by modify¡ing your command? (enable-MailUser)? What about the mailbox ?
November 18th, 2010 7:06am

IMHO, you need to spend some time learning Powershell, so that you can write and debug your own scripts. You've been at this quite a while now, and don't seem to be getting a handle on it. If the script isn't doing what you expect, break it down and start firguring out where it went wrong. Start with a .csv file with just a few addresses in it, and change the script to ouput some information about what it's doing. User,Address GRAIG,graig.lastname@company.com USER, user.lastname@company.com USER2,user2.lastname@company.com import-csv c:\somedir\addrlist.csv | foreach-object { write-host "User is $($_.user)" write-host "Address is $($_.primarysmtpaddress)" set-mailbox $_.User -primarysmtpaddress $_.address -verbose } You're not doing yourself any favors by coming back and saying "Somebody write me a script." everytime you run into a problem. [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 7:40am

I do not have testing environement and it is hard sometime to test things. I am far to be a specialist to create script and I do my best to understand them. Please do not feel oblidged to help me out if you don't feel like, I mainly mange project and am not left on creating only script, so when it regards things I cannot figure out myself I ask that great Forum, but maybe I should stop doing it if I'm welcome as is... Btw, I tried your command and it does not work.. Regards,
November 18th, 2010 8:56am

Well, as difficult as it is for you to work without a testing environment, consider how it is for someone trying to help you, without even any knowlege of or access to your systems. They cannot see your console, cannot see exactly what your input data looks like, or what errors or messages are being produced when you run a script. Anyone trying to help you is limited to only the information you provide. "It did not work" doesn't help much.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 9:07am

Sorry for not providing you more detail but I felt pretty bad providing your further information. I sort of figured out that you did not want to help me with this... So regarding your command, I ran it and when I hit enter and I got a row after the command like: User is GRAIG write-host Address is set-mailuser GRAIG -primarysmtpaddress graig.lastname@company.com When I look for the email address graig.lastname@company.com in EMC I got nothing even after a start edge sync. When I chcek the user's properties nothing has been added.
November 18th, 2010 12:24pm

If it's outputting this: User is GRAIG write-host Address is set-mailuser GRAIG -primarysmtpaddress graig.lastname@company.com It's writing the commands to the console instead of executing them. Exactly what did you run, and how did you run it? Are you copying the scripts to a file and running that, or did you type them in at an EMS command prompt , or just copy and paste it directly into the EMS? [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 12:42pm

I mainly mange project and am not left on creating only script, so when it regards things I cannot figure out myself I ask that great Forum, Do you have an Exchange administrator (someone who's trained on, or has studied Exchange administration)?[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 18th, 2010 12:58pm

On Thu, 18 Nov 2010 17:37:52 +0000, mjolinor wrote: > > >If it's outputting this: > >User is GRAIG write-host Address is set-mailuser GRAIG -primarysmtpaddress graig.lastname@company.com > >It's writing the commands to the console instead of executing them. Exactly what did you run, and how did you run it? Are you copying the scripts to a file and running that, or did you type them in at an EMS command prompt , or just copy and paste it directly into the EMS? Looks like a missing ending quotation mark is the promble -- at least to me. :-) --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 4:43pm

Looks like a missing ending quotation mark is the promble -- at least to me. :-) --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP If it was just a missing ending quote, you should get a parse error.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
November 18th, 2010 5:14pm

On Thu, 18 Nov 2010 22:03:06 +0000, mjolinor wrote: >Looks like a missing ending quotation mark is the promble -- at least to me. :-) --- Rich Matheisen MCSE+I, Exchange MVP Then the only other thing that would make that happen is that there's additional braces, like this: foreach { { code here } } --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 10:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics