Skip to content

/flags/entra-id/update-mguser-usagelocation

Update-MgUser -UsageLocation: set the country code required for licenses

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Microsoft Entra ID
command
Update-MgUser
flag
-UsageLocation <two-letter country code>
default
not set on users created without it (license assignment then fails)

Update-MgUser -UserId ID -UsageLocation "US" sets a Microsoft Entra ID user's usage location, a two-letter ISO 3166 country code. Microsoft 365 licensing needs it: the Graph user resource says usageLocation is "Required for users that are assigned licenses due to legal requirements to check for availability of services in countries/regions. Examples include: US, JP, and GB. Not nullable." Users created by scripts, synchronization or B2B invitations often lack it, and license assignment to them fails until it is set.

powershell
Connect-MgGraph -Scopes "User.ReadWrite.All"
Update-MgUser -UserId anna@contoso.com -UsageLocation "DE"
Get-MgUser -UserId anna@contoso.com -Property UserPrincipalName, UsageLocation |
  Select-Object UserPrincipalName, UsageLocation

Set it for users who have none

usageLocation "Requires $select to retrieve", so request it with -Property (Get-MgUser -Property) before filtering:

powershell
Get-MgUser -All -Property Id, UserPrincipalName, UsageLocation |
  Where-Object { -not $_.UsageLocation } |
  ForEach-Object { Update-MgUser -UserId $_.Id -UsageLocation "US" }

The user resource also says usageLocation supports $filter (eq, ne, not, ge, le, in, startsWith, and eq on null values), so the service can narrow the list instead of Where-Object.

The parameter in the module

Checked offline in Windows PowerShell 5.1 with Microsoft.Graph.Users 2.41.2: -UsageLocation is a plain string on both New-MgUser and Update-MgUser; PowerShell does not validate the country code, the service does.

powershell
Import-Module Microsoft.Graph.Users
foreach ($cmd in 'New-MgUser', 'Update-MgUser') {
  $p = (Get-Command $cmd).Parameters['UsageLocation']
  $vs = $p.Attributes | Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] }
  '{0} -UsageLocation: {1}, ValidateSet: {2}' -f $cmd, $p.ParameterType.Name, [bool]$vs
}
try { Update-MgUser -UserId anna@contoso.com -UsageLocation "DE" -ErrorAction Stop } catch { $_.Exception.Message }

Output

New-MgUser -UsageLocation: String, ValidateSet: False
Update-MgUser -UsageLocation: String, ValidateSet: False
Authentication needed. Please call Connect-MgGraph.

Where it matters

TaskWhy UsageLocation matters
Set-MgUserLicenseassigning a license to a user without it fails
Group-based licensingmembers without a usage location get a license error; the tenant default location may be used instead
New-MgUserset -UsageLocation at creation to avoid the problem
Moving a user to another countryservices that are not available in the new country may be removed

Pitfalls

  • Codes, not names. Germany or UK are not valid; use DE and GB.
  • Synced users. For accounts synchronized with Microsoft Entra Connect, the value can come from the on-premises attribute mapping; a cloud change may be overwritten on the next sync if that attribute is mapped.
  • Permissions. The admin needs a role that can manage users (for example User Administrator) and a Graph scope such as User.ReadWrite.All.
  • Then assign the license. See Set-MgUserLicense, and for new accounts New-MgUser with a password profile.

FAQ

Which value do I use for the United Kingdom?

GB, the ISO 3166 two-letter code, not UK. The Graph documentation gives US, JP and GB as examples.

Can I clear UsageLocation?

The user resource documents usageLocation as not nullable, so plan to change it to another country rather than removing it. Changing it can change which services are available to the user.

Is UsageLocation the same as the Country field?

No. Country (and City, State, OfficeLocation) are informational address fields. UsageLocation is the one licensing uses to check service availability.

Sources