License assignment failed – License cannot be assigned to a user without a usage location specified

By | July 9, 2022

If you are getting the error above when assigning licenses, it is because the entry UsageLocation isn’t set for the user.

This image has an empty alt attribute; its file name is Usagelocation.jpg

The quick way to fix the issue is obviously to set the entry manually.

If you want to apply the change to larger number of users, the code snippet below may help:

Connect-AzureAD 
Write-Host 'Please wait a moment...' -BackgroundColor DarkGreen -ForegroundColor White
$users = Get-AzureADUser
Write-Host 'Total number of users: '$users.Count
foreach($user in $users){
Try{
Set-AzureADUser -ObjectId $user.ObjectId -UsageLocation DE
Write-Host 'UsageLocation set for ' $user.DisplayName -BackgroundColor DarkGreen -ForegroundColor White
}
Catch{
Write-Host 'Something went wrong' -BackgroundColor DarkRed -ForegroundColor Yellow
Write-Host $_ -BackgroundColor DarkRed -ForegroundColor Yellow
}
}

Mind that there are alternative options, see the links below.

Links:

What is group-based licensing in Azure Active Directory?

https://docs.microsoft.com/en-us/azure/active-directory/fundamentals/active-directory-licensing-whatis-azure-portal

Set-AzureADUser

https://docs.microsoft.com/en-us/powershell/module/azuread/set-azureaduser?view=azureadps-2.0

Set Office 365 UsageLocation property with Azure automation

https://tech.nicolonsky.ch/office-usage-location-azure-automation/

Leave a Reply

Your email address will not be published. Required fields are marked *