Jump to content

Script to change the mail and primary SMTP address for bulk of users in the AD


Recommended Posts

Posted

Hi

 

We have windows 2012 domain controllers and the domain is Domain.com.

Under this I have a OU called STU and under this OU I have 5 sub OU’s

STU

-OU14

-OU15

-OU16

-OU17

-OU18

 

Each of these OUs have 200 users and now I would like to change the mail attribute and the primary SMTP address for every users

This value is under :User Properties-Attribute editor-Mail & proxyAddress

 

Example:

If I take the students under OU17, I would like to put 17 in front of their mail and SMTP address in the user attribute for evey user.

 

Please can a script be provided with syntax to do this task for all users in each of the OU.

Any help will be great and thanks in advance

Posted

When I click the link, it takes to the download archive and when I down the archive and extract the zip file

It gives the a list of folders- discussions, issues, license, release, source code and wiki.

I can’t see the installer file .

Please guide me if I am doing something wrong, and I need to get this sorted by tomorrow.

Thanks

Posted
Thanks I have downloaded the ADModify.exe and not familiar using this utility and don't want to mess up . Please can you take me through steps as per my AD structure as I posted first.
Posted

Launch the exe > Click on Modify Attributes > drop down the domain list - choose your domain > Choose your DC and click the green arrow.

 

Untick groups, contacts and public folders and untick show containers only to show the user objects - click the green arrow again.

 

Browse through the domain to your OU. highlight the OU and click on add to list. On the right of the window click select all - this will now edit the highlighted items. Now we need to go and edit the Email Address field.

 

What format are your email addresses in as this will build the string for your Primary email address.

 

The mail attribute is linked to the email field. I guess these are different to what the primary email address will be? or should this be the primary email address?

 

How many email addresses are in the attribute editor tab > Proxy Addresses as this is where the issue may arrise.

Posted

Thanks please see the attached and have gone till 3rd step

Example:

So at the moment the “mail” attribute for the current user is who is located in OU16 is [email protected] .

I would like to put 16 in front of all the users in OU16 and it needs be changed to this format: [email protected]

Also the same with the “Primary SMTP” address-need to put 16 for all the users in OU16 and the format needs to be [email protected]

These are the two values I need to change for all users really, so not sure on the AdModify .net , I need to select E-Mail Address tab or Custom

Will be easier to change the “mail” attribute first and second the Primary “SMTP” address

Any steps would be great

Custom attribute.bmp

Posted

right ok, ive just put a 17 in front of an ex staff member so i know this should work. Try it on one of your users first to see if it works.

 

In admodify select the Email addresses tab.

 

Tick Add SMTP Address and type this:

 

16%'mail'%

Tick set as primary and leave update email address on general tab ticked too

 

what this will do is take the mail attribute and alter the email addresses so it will add 16 to the existing entry setting it to primary and make the proxyaddresses the same too.

Posted (edited)

It gives this error as attached and also I noticed with the test account

Previous to running this software, the address was in this format the capital primary "SMTP:[email protected] ." in the AD account of the user( attribute)

 

When I ran this is shows as smtp:[email protected] " and it dosent put the vale of 14 for the primary SMTP address.

 

It must be in this format SMTP:[email protected]

SMTP error2.jpg

Edited by genesis
Posted (edited)

Its missing the other tick box next to set as primary. Ive just tried it on another ex staff member as used what youve set. I set the variable to 14%'mail'% and it only changed the proxyaddresses and didnt change the mail attribute.

 

Im not sure why its not applying. What about running the exe as administrator.

Edited by timbo343
Posted (edited)

Quick question, why does it need the SMTP:.... part? Are you running onprem exchange or do you connect to a cloud provider? Ive just checked a new member of staff as we connect to O365 and thsi user doesnt have the SMTP: variable part in their account.

 

Edit... none of our users have the SMTP:.. under proxyaddresses. I have it as i have so many alais however no one else has it, even those that were connected to our old onprem exhange server dont have it.

Edited by timbo343
Posted
I ran the exe as a domain\administrator and still it is doing the same. Iam running this on windows 2012 DC, do I need to run on our exchange 2013?
Posted

No you shouldnt need to, i run it on my win10 machine connecting to one of our 2012 r2 DCs and we were using exchange 2010 before o365.

 

What are you seeing in the attributes tab of AD? What is changing in there?

Posted

We have on prem Exchange and have migrated the mail box to 0365. Because we changed the email domain name and the new domain must contain the SMTP value with 14 .

The old address has the 14 in front of the email address in the attributes , but not the new email domain SMTP address.

sorry for the trouble , need to resolve this by tomorrow morning

Posted
Please see the attached of snapshot of attribute editor and when I run the ADModify.exe, it only changes the SMTP into small letters smtp and it doesn't put 14 in from of the email address.

attribute editor3.jpg

Posted
Please see the snap shot of the attribute editor. When run the Ad modify , it changes the SMTP into lowercase smtp and doesn'tattribute editor3.jpg put14 in front of the email address.
Posted
Please see the snap shot of the attribute editor. When run the Ad modify , it changes the SMTP into lowercase smtp and doesn't put 14 in front of the email address.attribute editor3.jpg
Posted
Ah! I see the issue and without seeing it live im struggling. Im startng to think this is going to be a bigger job than what i thought it was. Im wondering if it wont set it to the primary address as it already has a primary address there. I have a feeling that you may need to export the addresses to csv work on them then import telling powershell which column is the primary address.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...