If you are getting the error above when assigning licenses, it is because the entry UsageLocation isn’t set for the user.
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?
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/