I'm trying to remove multiple licences from a user or users within my .xlsx file. Here is my code
$users = Import-XLSX '\\server\c$\User Creation\ADUsersRemoval.xlsx' |
where {$_.isLicensed -eq $true}
foreach ($user in $users)
{
$Firstname = $User.Firstname
$Lastname = $User.Lastname
$upn= "[email protected]"
Set-MsolUserLicense -UserPrincipalName $upn -RemoveLicense "Domain:POWER_BI_STANDARD","Domain:FLOW_FREE"
}
I keep getting the error
Set-MsolUserLicense : Unable to assign this license because it is invalid. Use the Get-MsolAccountSku cmdlet to retrieve a list of valid licenses.
Personally I think its because some users may not have one of those licences. If I want to remove one licence and they all had the same licence it would work fine but with two licences and some users don't have both, it just throws up the error.
Any help on this would be appreciated.