Replies: 1 comment
-
|
This works great when you know that you have available licenses. I've created a somewhat different scriptlet to do the same but also report sku's that I don't have available licenses for as part of a general onboarding script. $SourceUserUPN is filled with the UPN of the source user while $UPN is filled with the UPN of the newly created or target user. $mgSourceLicenses = (Get-MgUser -UserId $SourceUserUPN -Property AssignedLicenses).AssignedLicenses
$mgLicenseAvailability = get-mgsubscribedsku | where {$_.SkuId -in $mgSourceLicenses.SkuId} | select -Property Sku*, ConsumedUnits -ExpandProperty PrepaidUnits | select @{Name = 'Available'; Expression = {$_.Enabled - $_.ConsumedUnits}}, SkuId, SkuPartNumber
#Appoint licenses that are available, report on those that aren't
$mgLicenseAvailability | % {
if ($_.Available -eq 0) {
$mgLicenseError += $_.SkuPartNumber
}
else {
Set-MgUserLicense -UserId $UPN -AddLicenses @{SkuId = $_.SkuId} -RemoveLicenses @()
}
}If you then add a license list to your script that has a translation between the Sku part numbers and the friendly name you can create very userfriendly error messages stating which licenses haven't been added because they aren't available. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This example assigns jamesp@litwareinc.com with the same licensing plan that has been applied to belindan@litwareinc.com.
Beta Was this translation helpful? Give feedback.
All reactions