Wednesday, June 4, 2014

Office 365: fix the UserPrincipalName if you synced AD prior to adding the new UPN suffix


Probably like many people, I started testing out Office 365 in phases. One change that we had to make was to add a UPN alias for @domain.org to replace our @domain.local. I was a little leery of this, so I tested out some Office 365 features before adding the domain alias, including adding licenses to about 20 of our accounts.

The problem: those accounts that I just synced up were stuck with the ugly @domain.onmicrosoft.com domain, instead of our nice @domain.org alias. Forcing a resync did not resolve it.

This Technet article explains very clearly how to fix the problem:

Open Windows Azure Active Directory Module for Powershell, and then type in:
 
Set-MsolUserPrincipalName -UserPrincipalName user1@domain.onmicrosoft.com -NewUserPrincipalName user1@domain.org 

Simple, but I didn't want to run this dumb command one at a time for each account. Simple enough in powershell, but I ran into a few gotchas so here is the successful command line I ran:

Get-MsolUser -domainname "domain.onmicrosoft.com" | where islicensed -eq $true | %{Set-MsolUserPrincipalName -userprincipalname $_.userprincipalname -NewUserPrincipalName($_.userprincipalname.replace("@DOMAIN.onmicrosoft.com","@domain.org"))}




One thing that took me a minute to remember after several runs with nothing happening is that string.replace() method is case sensitive, so make sure that you properly capitalize the UPN that you want to replace.

Monday, June 2, 2014

Bulk Import photos into Active Directory for Sharepoint, Outlook 2010, Outlook 2013 and Lync

A simple Powershell script to import photos from a directory into AD. The photos should be named with the format "samAccountName.jpg", less than 10k in size, and recommended dimensions of 96x96.

To get the photos into the proper format, I used imageMagick's "mogrify" command.

mogrify -path OUTPUT_PATH -format jpg -thumbnail 96x96 *.jpg

Embedded github "Gist":