One of the more tedious tasks in Office 365 is setting the user usage location. This is a requirement prior to licensing.  In large, global organizations, you may have multiple usage locations that you need to set.  This script is based on the ISO country code list and will allow you to set the country code in Active Directory and then configure the user's corresponding Windows Azure Active Directory ID with the same usage location.


Office 365 Tenant
Directory Synchronization Activated and Configured
Active Directory country code field updated for users


  1. Configure all users in Active Directory with an appropriate country code.  You can select user objects globally, at an OU level or using a tool like ADModify.
  2. Force (or wait) for Directory Synchonization to your Office 365 tenant.
  3. Log into your tenant and run this script.

It has two operating modes--report and update.  Report will show you user-by-user what it was able to detect as the country code and what will need to be set.  Update will make the changes.  Users with no country code will appear in red.

Alternately, if you have upgraded to AADConnect, check out my blog post on using an AADConnect sync rule to fill in this data at