|
1 |
| -### Example 1: {{ Add title here }} |
| 1 | +### Example 1: Assign a license to a user |
| 2 | + |
| 3 | +```powershell |
| 4 | +Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All |
| 5 | +
|
| 6 | +$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM' |
| 7 | +
|
| 8 | +Set-MgUserLicense -UserId '38955658-c844-4f59-9430-6519430ac89b' -AddLicenses @{SkuId = $EmsSku.SkuId} -RemoveLicenses @() |
| 9 | +
|
| 10 | +Id DisplayName Mail UserPrincipalName UserType |
| 11 | +-- ----------- ---- ----------------- -------- |
| 12 | +38955658-c844-4f59-9430-6519430ac89b Bianca Pisani [email protected] Member |
| 13 | +``` |
| 14 | + |
| 15 | +This example assigns a license from the **EMSPREMIUM** (ENTERPRISE MOBILITY + SECURITY E5) licensing plan to the unlicensed user **38955658-c844-4f59-9430-6519430ac89b**. For more information, see [assign licenses to users accounts with PowerShell](/microsoft-365/enterprise/assign-licenses-to-user-accounts-with-microsoft-365-powershell?view=o365-worldwide). |
| 16 | + |
| 17 | +### Example 2: Assign more than one licenses to a user |
| 18 | + |
| 19 | +```powershell |
| 20 | +Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All |
| 21 | +
|
| 22 | +$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM' |
| 23 | +$FlowSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'FLOW_FREE' |
| 24 | +$addLicenses = @( |
| 25 | + @{SkuId = $EmsSku.SkuId}, |
| 26 | + @{SkuId = $FlowSku.SkuId} |
| 27 | + ) |
| 28 | +
|
| 29 | +Set-MgUserLicense -UserId '38955658-c844-4f59-9430-6519430ac89b' -AddLicenses $addLicenses -RemoveLicenses @() |
| 30 | +
|
| 31 | +Id DisplayName Mail UserPrincipalName UserType |
| 32 | +-- ----------- ---- ----------------- -------- |
| 33 | +38955658-c844-4f59-9430-6519430ac89b Bianca Pisani [email protected] Member |
| 34 | +``` |
| 35 | + |
| 36 | +This example assigns **EMSPREMIUM** and **FLOW_FREE** licenses to the user **38955658-c844-4f59-9430-6519430ac89b**. |
| 37 | + |
| 38 | +### Example 3: Assign a license to a user with some disabled plans |
| 39 | + |
| 40 | +```powershell |
| 41 | +Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All |
| 42 | +
|
| 43 | +$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM' |
| 44 | +$disabledPlans = $EmsSku.ServicePlans | where ServicePlanName -in ("MFA_PREMIUM", "INTUNE_A") | Select -ExpandProperty ServicePlanId |
| 45 | +$addLicenses = @( |
| 46 | + @{SkuId = $EmsSku.SkuId |
| 47 | + DisabledPlans = $disabledPlans |
| 48 | + } |
| 49 | + ) |
| 50 | +
|
| 51 | +Set-MgUserLicense -UserId '38955658-c844-4f59-9430-6519430ac89b' -AddLicenses $addLicenses -RemoveLicenses @() |
| 52 | +
|
| 53 | +Id DisplayName Mail UserPrincipalName UserType |
| 54 | +-- ----------- ---- ----------------- -------- |
| 55 | +38955658-c844-4f59-9430-6519430ac89b Bianca Pisani [email protected] Member |
| 56 | +``` |
| 57 | + |
| 58 | +This example assigns **EMSPREMIUM** license with the **MFA_PREMIUM** and **INTUNE_A** services turned off. |
| 59 | + |
| 60 | +### Example 4: Update a license assigned to a user to add more disabled plans leaving the user's existing disabled plans in their current state |
| 61 | + |
2 | 62 | ```powershell
|
3 |
| -PS C:\> {{ Add code here }} |
| 63 | +Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All |
| 64 | +
|
| 65 | +$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM' |
| 66 | +$userLicense = Get-MgUserLicenseDetail -UserId "38955658-c844-4f59-9430-6519430ac89b" |
| 67 | +
|
| 68 | +$userDisabledPlans = $userLicense.ServicePlans | |
| 69 | + Where ProvisioningStatus -eq "Disabled" | |
| 70 | + Select -ExpandProperty ServicePlanId |
4 | 71 |
|
5 |
| -{{ Add output here }} |
| 72 | +$newDisabledPlans = $EmsSku.ServicePlans | |
| 73 | + Where ServicePlanName -in ("AAD_PREMIUM_P2", "AAD_PREMIUM") | |
| 74 | + Select -ExpandProperty ServicePlanId |
| 75 | +
|
| 76 | +$disabledPlans = $userDisabledPlans + $newDisabledPlans | Select -Unique |
| 77 | +
|
| 78 | +$addLicenses = @( |
| 79 | + @{SkuId = $EmsSku.SkuId |
| 80 | + DisabledPlans = $disabledPlans |
| 81 | + } |
| 82 | + ) |
| 83 | +
|
| 84 | +Set-MgUserLicense -UserId '38955658-c844-4f59-9430-6519430ac89b' -AddLicenses $addLicenses -RemoveLicenses @() |
| 85 | +
|
| 86 | +Id DisplayName Mail UserPrincipalName UserType |
| 87 | +-- ----------- ---- ----------------- -------- |
| 88 | +38955658-c844-4f59-9430-6519430ac89b Bianca Pisani [email protected] Member |
6 | 89 | ```
|
7 | 90 |
|
8 |
| -{{ Add description here }} |
| 91 | +This example updates the **EMSPREMIUM** license assigned to the user to add **AAD_PREMIUM_P2** and **AAD_PREMIUM** to the disabled services. |
| 92 | + |
| 93 | +### Example 5: Assign licenses to a user by copying the license assignment from another user |
9 | 94 |
|
10 |
| -### Example 2: {{ Add title here }} |
11 | 95 | ```powershell
|
12 |
| -PS C:\> {{ Add code here }} |
| 96 | +Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All |
13 | 97 |
|
14 |
| -{{ Add output here }} |
| 98 | +Select-MgProfile -Name Beta |
| 99 | +$mgUser = Get-MgUser -UserId '38955658-c844-4f59-9430-6519430ac89b' |
| 100 | +
|
| 101 | +Set-MgUserLicense -UserId "82f51c98-7221-442f-8329-3faf9fe022f1" -AddLicenses $mgUser.AssignedLicenses -RemoveLicenses @() |
| 102 | +
|
| 103 | +
|
| 104 | +Id DisplayName Mail UserPrincipalName UserType |
| 105 | +-- ----------- ---- ----------------- -------- |
| 106 | +82f51c98-7221-442f-8329-3faf9fe022f1 Mallory Cortez [email protected] Member |
15 | 107 | ```
|
16 | 108 |
|
17 |
| -{{ Add description here }} |
| 109 | +This examples copies the license assignment of user **38955658-c844-4f59-9430-6519430ac89b** and assigns it to user **82f51c98-7221-442f-8329-3faf9fe022f1**. |
| 110 | + |
| 111 | +### Example 6: Remove a license assigned to a user |
| 112 | + |
| 113 | +```powershell |
| 114 | +Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All |
| 115 | +
|
| 116 | +$EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM' |
| 117 | +
|
| 118 | +Set-MgUserLicense -UserId "38955658-c844-4f59-9430-6519430ac89b" -AddLicenses @() -RemoveLicenses @($EmsSku.SkuId) |
| 119 | +
|
| 120 | +Id DisplayName Mail UserPrincipalName UserType |
| 121 | +-- ----------- ---- ----------------- -------- |
| 122 | +38955658-c844-4f59-9430-6519430ac89b Bianca Pisani [email protected] Member |
| 123 | +``` |
18 | 124 |
|
| 125 | +This example removes the **EMSPREMIUM** license assignment from the user. |
0 commit comments