Solved

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

Posted on 2015-01-05
12
412 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
  • 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
 
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

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Synchronize a new Active Directory domain with an existing Office 365 tenant
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now