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

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.
HCSHAWAsked:
Who is Participating?
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
HCSHAWAuthor Commented:
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
 
HCSHAWAuthor Commented:
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
Will SzymkowskiSenior Solution ArchitectCommented:
Perfect,

Let me know if you need any other assistance.

Will
0
 
HCSHAWAuthor Commented:
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
 
HCSHAWAuthor Commented:
Side Note:  File contents is BEFORE corrections are inputted.
0
 
Will SzymkowskiSenior Solution ArchitectCommented:
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
 
HCSHAWAuthor Commented:
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
 
HCSHAWAuthor Commented:
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
 
HCSHAWAuthor Commented:
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
 
Will SzymkowskiSenior Solution ArchitectCommented:
That is odd, it should have worked with one script. Anyways glad that it worked for you!

Will.
0
 
HCSHAWAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.