{"id":1027,"date":"2019-12-05T10:57:13","date_gmt":"2019-12-05T02:57:13","guid":{"rendered":"http:\/\/blog.wallaceho.com\/?p=1027"},"modified":"2019-12-05T10:57:50","modified_gmt":"2019-12-05T02:57:50","slug":"assign-o365-license-by-powershell","status":"publish","type":"post","link":"https:\/\/blog.wallaceho.com\/?p=1027","title":{"rendered":"Assign O365 license by PowerShell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Assigning license to a group of O365 users are always the most headache task for administrators. So why don&#8217;t we script it? Let&#8217;s start!<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p class=\"wp-block-paragraph\">First of all, check the license plan and usage of your company.<\/p>\n<\/div><\/div>\n\n\n\n<pre class=\"wp-block-code\"><code>Connect-AzureAD #Connect to the tenant\n\nGet-AzureADSubscribedSku | Select SkuPartNumber #Show account service plan and grep the SkuPartNumber (e.g, Microsoft 365 E3 = ENTERPRISEPACK, Microsoft 365 F1 = SPE_F1)\n\n#Check SKU Service Plan detail option from the above output. Let's say if there are 22 SkuPartNumber in your service plan, you would like to select the 19th one, fill in 18 in the array of $license\n$licenses = Get-AzureADSubscribedSku\n$licenses&#91;18].ServicePlans<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the output, so now you got all of the information of your account license that you want to add. The next step is define the service plan you would like to activate for the group of users. Create a csv file, define the license option (The output above); Friendly Name; Add License Option (True or False).  Below are the example, we would like to enable Microsoft Search, Skype for Business, Office Online and Exchange Online but disable Microsoft Teams.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LicenseOption;FriendlyName;addLicenseOption\nMICROSOFT_SEARCH;Microsoft Search;yes\nTEAMS1;Microsoft Teams;no\nMCOIMP;Skype for Business Online;yes\nSHAREPOINTWAC;Office Online;yes\nEXCHANGE_S_DESKLESS;Exchange Online Kiosk;yes<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create another csv and import the SMTP addresses that you would like to add the licenses.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>smtpAddress\nxx.xx@ABC.com\nxxx.xxx@ABC.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, the main PowerShell script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Powershell for license assignment                                                                                #\n# Author: Wallace Ho                                                                                                     #\n# Version: 1.0                                                                                                           #\n\n\n$users = Import-Csv \"C:\\Users\\wallaceho\\Desktop\\Licenses\\users.csv\" -Delimiter \";\" # Define SMTP address CSV file path\n$additionalOptions = Import-Csv \"C:\\Users\\wallaceho\\Desktop\\Licenses\\licenseplan.csv\" -Delimiter \";\" | ?{$_.addLicenseOption -eq \"no\"} #License path filter for disable option\n\nforeach ($user in $users) #for each user in the SMTP address CSV file path\n{\n    $opts = New-MsolLicenseOptions -AccountSkuId \"&lt;accountid:serviceplan>\" \u2013DisabledPlans $additionalOptions.LicenseOption #Define disable option, remember to change the &lt;accountid:serviceplan>\n    Set-MsolUserLicense -UserPrincipalName $user.smtpAddress -RemoveLicenses &lt;accountid:serviceplan>  #Remove old license, remember to change the &lt;accountid:serviceplan>\n    Set-MsolUserLicense -UserPrincipalName $user.smtpAddress -AddLicenses &lt;accountid:serviceplan> -LicenseOptions $opts #Add new license, remember to change the &lt;accountid:serviceplan>\n}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Assigning license to a group of O365 users are always the most headache task for administrators. So why don&#8217;t we script it? Let&#8217;s start! First of all, check the license plan and usage of your company. Copy the output, so &hellip; <a href=\"https:\/\/blog.wallaceho.com\/?p=1027\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1027","post","type-post","status-publish","format-standard","hentry","category-computer"],"_links":{"self":[{"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=\/wp\/v2\/posts\/1027","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1027"}],"version-history":[{"count":12,"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=\/wp\/v2\/posts\/1027\/revisions"}],"predecessor-version":[{"id":1081,"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=\/wp\/v2\/posts\/1027\/revisions\/1081"}],"wp:attachment":[{"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wallaceho.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}