Import-Module MSOnline
$cred = Get-Credential
Connect-MsolService -Credential $cred
$oldLicense = "contoso:ENTERPRISEPACK"
$newLicense = "contoso:ENTERPRISEPREMIUM"
$users = Get-MsolUser -MaxResults 5000 | Where-Object { ($_.isLicensed -eq "TRUE" -and $_.city -eq "Mumbai")}
foreach ($user in $users){
$upn = $user.UserPrincipalName
foreach ($license in $user.Licenses) {
if ($license.AccountSkuId -eq $oldLicense) {
$disabledPlans = @()
Write-Host("User $upn will go from $oldLicense to $newLicense and will have no options disabled.")
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses $newLicense -RemoveLicenses $oldLicense
}
}
}
But I suggest to manage License using AD Groups.
If you find my reply helpful, please “Mark as Answer” and “Vote”
Get help on demand expertise-as-a-service.com