Hi,
I’m trying to remove all the licenses from a given user in 0365
when I try to execute this code
[pre]
$csvFileLocation = “c:\temp\csv\toRemove.csv”
$users = Import-Csv -Path $csvFileLocation
foreach ($user in $users) {
$upn = $user.UserPrincipalName
(get-MsolUser -UserPrincipalName $upn).licenses.AccountSkuId |
foreach{
Set-MsolUserLicense -UserPrincipalName $upn -RemoveLicenses $_
}
}[/pre]
then I get this error
[pre]
Set-MsolUserLicense : Unknown error occurred.
At line:5 char:9
Olaf,
I know that for the Office365 the user is put in a security group in AD to be able to use office when I look up the same user in AzureAD then I see this info if this is usefull to you
Communications Credits
Active
1/1
Inherited (Office365License-Users)
Enterprise Mobility + Security E5
Active
9/9
Inherited (Office365License-Users)
Office 365 E5
Active
36/39
Inherited (Office365License-Users)
or do I need to remove the licenses directly from azureAD?
Update:
removing the license from on Prem AD sorted this out
You can remove the licenses this way only when you assigned them directly. … it’s a kind of logic … when you remove the license while the according group membership is still “active” the license will “come back”.