Friday, August 30, 2013

Enable Specific Office 365 Licenses using PowerShell

I found myself recently with the need to assign specific licenses within the Enterprise Pack to Office 365 users from PowerShell. This is fairly trivial from the Portal web interface, but when you assign a license using the following command it assigns ALL the licenses in the Enterprise Pack:

Set-MsolUserLicense -UserPrincipalName "lynctest@domain.com" -AddLicenses <Office365Sku>

This is fine if that is what you want, but my customer wanted to only assign the Lync Online license


So I set about trying to figure out how to do it. I found the pieces to the answer in several different places... so I figured I'd put it all together in one blog post.

First off... you need to get your account SKU

PS C:\scripts> Get-MsolAccountSku
AccountSkuId                    ActiveUnits     WarningUnits    ConsumedUnits
------------                    -----------     ------------    ----
somecustomer:ENTERPRISEPACK      1000            0               127


If you have more than one... pick the appropriate one and place that in the variable $office365sku below.

Okay... now pay attention... the next variable is the licenses we want to DISABLE. Yes that is right... we enable all the licenses first, and then we disable what we don't want. To see the different options enter this command:

PS C:\scripts> Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq 'ENTERPRISEPACK'} | ForEach-Object {$_.ServiceStatus}

ServicePlan                             ProvisioningStatus
-----------                             ------------------
RMS_S_ENTERPRISE                        Success
OFFICESUBSCRIPTION                      Success
MCOSTANDARD                             Success
SHAREPOINTWAC                           Success
SHAREPOINTENTERPRISE                    Success
EXCHANGE_S_ENTERPRISE                   Success


The order above matches the order in the Portal web interface.

Just a side note, the "Office Web Apps" is not needed for Lync Online. The Office Web Apps license has to do with SharePoint Office Web Apps, not the Office Web Apps used with Lync Online.

So... in the $options variable below you need to modify the licenses you want to disable. Below is an example of the licenses disabled to only leave Lync Online enabled.

That's it... enjoy.


# Script to Enable Specific Office 365 Licenses using PowerShell
# Created By Jonathan McKinney (blog.lyncdialog.com)
# Time2Market 2013


$msoluser = "lynctest at domain.com"
$office365sku = "somecustomer:ENTERPRISEPACK"
$options = New-MsolLicenseOptions -AccountSkuId $office365sku -DisabledPlans RMS_S_ENTERPRISE,OFFICESUBSCRIPTION,SHAREPOINTWAC,SHAREPOINTENTERPRISE,EXCHANGE_S_ENTERPRISE

$transcriptname = “Office365License” + `
    (Get-Date -format s).Replace(“:”,”-”) +”.txt”
Start-Transcript $transcriptname

  Write-Host  `r
  Write-Host  `r`n 'Enable licenses for ' $msoluser `r`n
  Set-MsolUser -UserPrincipalName $msoluser -UsageLocation US
  Set-MsolUserLicense -UserPrincipalName $msoluser -AddLicenses $office365sku
  Set-MsolUserLicense -UserPrincipalName $msoluser -LicenseOptions $options
  Write-Host  `r


Stop-Transcript

10 comments:

  1. Good article. Clear and concise.

    ReplyDelete
  2. Grateful to check out your website, I seem to be ahead to more excellent sites and I wish that you wrote more informative post for us. Well done work.

    ReplyDelete
  3. So, Microsoft must have changed something in the last two years (no surprise there).. using this exact script and getting "license options are invalid". Adds the license, but doesn't do the exclusions. Can anyone point me in the right direction for a current method of achieving this?

    ReplyDelete
    Replies
    1. If you do this command you might find that there are more or different license options now than what I have listed.

      Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq 'ENTERPRISEPACK'} | ForEach-Object {$_.ServiceStatus}

      the area below of the script will need to have the licenses modified to match the command I mentioned earlier and remove the ones you want actually enabled.

      $options = New-MsolLicenseOptions -AccountSkuId $office365sku -DisabledPlans RMS_S_ENTERPRISE,OFFICESUBSCRIPTION,SHAREPOINTWAC,SHAREPOINTENTERPRISE,EXCHANGE_S_ENTERPRISE

      hopefully this helps...

      Delete
    2. you might also need to start with this command Get-MsolAccountSku to determine if you have the "ENTERPRISEPACK" licenses or not... may be something totally different

      Delete
    3. Correct, run get-msolacountsku and get:
      AccountSkuId
      ------------
      MillersvilleUniversity:STANDARDWOFFPACK_IW_FACULTY
      MillersvilleUniversity:STANDARDWOFFPACK_STUDENT
      MillersvilleUniversity:STANDARDWOFFPACK_IW_STUDENT
      MillersvilleUniversity:PLANNERSTANDALONE
      MillersvilleUniversity:STANDARDWOFFPACK_FACULTY

      been using the STANDARDWOFFPACK_IW_STUDENT

      Delete
    4. so now you need to do

      Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq 'STANDARDWOFFPACK_IW_FACULTY'} | ForEach-Object {$_.ServiceStatus}

      so you can see the individual licenses for STANDARDWOFFPACK_IW_FACULTY

      Delete
    5. or change out the sku for any of the other packs you have

      Delete
  4. PS C:\> Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq 'STANDARDWOFFPACK_IW_STUDENT'} | Fo
    rEach-Object {$_.ServiceStatus}

    ServicePlan ProvisioningStatus
    ----------- ------------------
    OFFICE_FORMS_PLAN_2 Success
    PROJECTWORKMANAGEMENT Success
    SWAY Success
    YAMMER_EDU Success
    SHAREPOINTWAC_EDU Success
    SHAREPOINTSTANDARD_EDU Success
    EXCHANGE_S_STANDARD Success
    OFFICESUBSCRIPTION Success
    MCOSTANDARD Success


    I'm trying to assign license and exclude "EXCHANGE_S_STANDARD"..

    OH WAIT!! I see it.. I left the service as "EXCHANGE_S_ENTERPRISE" when I changed your script. OH THANK YOU !! Just typing this out made me see my error !!!!

    ReplyDelete