We help IT Professionals succeed at work.

UserPrincipalName Blank - How to set it for multiple users?

3,289 Views
Last Modified: 2011-10-19
Windows Server 2008.  Domain upgraded from 2000.  around 6000 users.

I, for some unknown reason, have a lot of users with a blank UserPrincipalName field. At least I think that is the field it is called.  If you go into ADUC,to the users ACCOUNT tab, you see there user account name, but the field next to it, the dropdown for the domain name, is blank. I could go into each user and select the domain from the dropdown but that is not going to be fun.  I am looking for an automated way to set this for any user who has it blank. Powershell hopefully?

FYI, the reason I need it set is that Exchange 2007 will not create a mailbox for any user who has this set.
BlankPic.jpg
Comment
Watch Question

$users = get-user

foreach ($user in $users) {
# check if null
if ( $user.UserPrincipalName -eq $null ) {
# set is equal to samaccountname
$upn= $user.samaccountname + "@upn.com"
set-user $user -userprincipalname $upn

}
}

Note: This is untested sample but this should work for you.
CERTIFIED EXPERT

Author

Commented:
This looks good. As soon as I can figure out how to list users (get-user and set-user are not valid commands), I will award the points.
You will find these commands in exchange management shell.
CERTIFIED EXPERT

Author

Commented:
Possibly for every user it gives me this message:
WARNING: Object xyc.com/ACCOUNTING/john Doe has been corrupted and it is in an inconsistent state. The following validation errors have occurred:
WARNING: "jdoe" is not valid for UserPrincipalName. Valid values are:
Strings that included '@', where '@' cannot be the last character.

And it doesn't make the change. Thoughts?
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Author

Commented:
I liked where Suhhirchauhan3's answer led me. Gave me good examples. I actually used ADModify to fix it in the end but I think, had I been more patient, S's answer would have worked.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.