Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2015-01-05
12
Medium Priority
?
716 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 2000 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

596 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