I'm looking for a way to add an E3 or E1 license to a user based on the availability of the license.
For example: if there's no E3 license anymore, add then an E1 license
What I do, I use the "Set-MsolUserLicense" command on 2 lines. If the first line gives an error like, no more available. Then it goes to the 2nd line and executes the second one.
If the first line goes without error and it goes to 2nd line and then it gives an error, already license added.
So that's my way :)
Any ideas how it must be? :)
Wkr, M
CodePudding user response:
Based on the above shared requirement we have written the below powershell script will check the current units of licences available & assign the user with appropriate license accordingly either e3 or e1.
Connect-MsolService
$userlist={'[email protected]','[email protected]'}
foreach($users in $userlist){
$e3= Get-MsolAccountSku | Where AccountSkuId -Contains microsoft:ENTERPRISEPACK
$e1= Get-MsolAccountSku | Where AccountSkuId -Contains microsoft:STANDARDPACK
if( $e3.ConsumedUnits -le $e3.ActiveUnits){
Write-Host "Need to append e3"
Set-MsolUserLicense -AddLicenses $e3.AccountSkuId -UserPrincipalName $users
}
elseif( $e1.ConsumedUnits -le $e1.ActiveUnits){
Write-Host "Need to append e1"
Set-MsolUserLicense -AddLicenses $e3.AccountSkuId -UserPrincipalName $users
}
else{
Write-host "No active E1 or E3 Linceses available for the current tenant"
}
}
You can refer this documentation for more information about Product names and service plan identifiers for licensing