Solved

How do I update in Active Directory the attribute "MAIL"

Posted on 2015-01-05
12
578 Views
Last Modified: 2015-01-06
Issue:
In investigating Google Password Sync to determine why it is not syncing when a user makes a password change, I discovered that the Users attribute in the ACTIVE DIRECTORY USERS  is set to his nickname@domain.com when it should be FLastname@domain.com.  Google expects the username to match in the domain and in Google Apps.  Our Google Apps user name is FLastname@domain.com.

How do I do a mass update to change the attribute from nickname@ to FLastname@?  Or how do I get a list of what they are so  I can identify the ones that need to be fixed.

Windows 2008 r2 sever is the Primary, and we have two secondary domain controllers that are W2K R2.

I can go in and EDIT each user, but that could be time consuming.   Yet, doing a mass update can be problematic in that some users "MAIL" is already  FLastname.
0
Comment
Question by:HCSHAW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
12 Comments
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 500 total points
ID: 40531690
I am assuming that you are talking about the UPN (UserPrincipalName attribute)?

You can do this all via powershell...
Export All Users with their UPN
get-aduser -filter * -properties * | select name, UserPrincipalName, sAMAccountName | export-csv c:\exportedusers.csv

Open in new window


Once you have the first exported list remove the ones that are setup using first/lastname. Modify the UserPrincipalName so that it shows the correct values firstnamelastname@domain.com. In Excel you can use the Name column and concatenate to get the correct values.

Keep 2 column heading sAMAccountName and UserPrincipalName

Import-module activedirectory
$Users = import-csv c:\changeusers.csv"
foreach ($User in $Users) {
$User.sAMAccountName
$User.UserPrincipalName
Set-AdUser -Identity $User.sAMAccountName -UserPrincipalName $User.UserPrincipalName
}

Open in new window


You can also just test this with one user in the CSV before proceeding to do all of them.

Will.
0
 

Author Comment

by:HCSHAW
ID: 40531706
Will,
That looks close to what I need.   The Attribute field I need to manipulate is not the  user name, but the one referred to as "MAIL' and "MailNickName".   How would I modify your code to look at that attribute and change it, and then import back in?
0
 

Author Comment

by:HCSHAW
ID: 40531729
Will,
Hold up, I think I;ve got it.   As you can tell I am not a whiz with powershell.  :)   I see where the fieldnames go.   I am experimenting now.  WIll get back to you with the results.
Thanks,
Harry
0
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40531822
Perfect,

Let me know if you need any other assistance.

Will
0
 

Author Comment

by:HCSHAW
ID: 40531989
Please review the code and see if you agree that this should work in replacing the Mail and MailNickName attributes of a user

Extract PS
get-aduser -filter * -properties * | select name, Mail, MailNickName, sAMAccountName | export-csv c:\ExportUsers.csv

Cleaned up
Make corrections to Mail and MailNickName and save file as LoadUsers.csv

File contents:
#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser
"name","Mail","MailNickName","sAMAccountName"
"KHappy","Happy@matheselectric.com","KHappy","KHappy"



Load
Import-module activedirectory
$Users = import-csv c:\LoadUsers.csv"
foreach ($User in $Users) {
$User.sAMAccountName
$User.Mail
$User.MailNickName
Set-AdUser -Identity $User.sAMAccountName -Mail $User.Mail    
Set-AdUser -Identity $User.sAMAccountName -MailNickName $User.MailNickName
}
0
 

Author Comment

by:HCSHAW
ID: 40531996
Side Note:  File contents is BEFORE corrections are inputted.
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40532122
You don't need the additional line of code. See below...

Import-module activedirectory
$Users = import-csv c:\LoadUsers.csv"
foreach ($User in $Users) {
$User.sAMAccountName
$User.Mail
$User.MailNickName
Set-AdUser -Identity $User.sAMAccountName -Mail $User.Mail -MailNickName $User.MailNickName
}

Will.
0
 

Author Comment

by:HCSHAW
ID: 40532322
It gives me an error :
Test Run
PS C:\scripts> .\loaduser.ps1
KHappy
Happy
KHappy@matheselectric.com
Set-ADUser : A parameter cannot be found that matches parameter name 'Mail'.
At C:\scripts\LoadUser.ps1:7 char:48
+ Set-AdUser -Identity $User.sAMAccountName -Mail <<<<  $User.Mail -MailNickNam
e $User.MailNickName
    + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBind
   ingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory
   .Management.Commands.SetADUser

Here is the test load file

#TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser
"Mail","MailNickName","sAMAccountName"
"KHappy@matheselectric.com","Happy","KHappy"


Any idea why the error?
0
 

Author Comment

by:HCSHAW
ID: 40532326
Here is the Power Shell Script:
import-module activedirectory
$Users = import-csv "c:\scripts\LoadUser.csv"
foreach ($User in $Users) {
$User.sAMAccountName
$User.MailNickName
$User.Mail
Set-AdUser -Identity $User.sAMAccountName -Mail $User.Mail -MailNickName $User.MailNickName
}
0
 

Author Comment

by:HCSHAW
ID: 40532531
Here is a script that would run.   I couldn't get it to update both fields, so I did two scripts, one for Mail, the other for MailNickName.

import-module activedirectory
$Users = import-csv -path c:\scripts\PnsLoadUser.csv
foreach ($User in $Users) {
$User.sAMAccountName
$User.MailNickName
$User.Mail
Set-AdUser -Identity $User.sAMAccountName -replace @{Mail="$($User.Mail)" }
}
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 40532626
That is odd, it should have worked with one script. Anyways glad that it worked for you!

Will.
0
 

Author Closing Comment

by:HCSHAW
ID: 40533366
Thanks for the pointers and feedback.   This script had issues with running, but after tweaking I was able to get a script that would run.   It was included in my last post for those that are following along.   Your help saved me hours of figuring it out.  Again, I am most appreciative.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question