?
Solved

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

Posted on 2015-01-05
12
Medium Priority
?
649 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
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.
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 …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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