Recently I was asked to look into migrating some on-premise Exchange 2010 archives to Office 365.

In order to do so you must first license each user on Office 365 in order to migrate their archive. I had a fairly large number of users to license in Office 365 so I thought that there was bound to be a script out there to accomplish this. My searches took me to Roman Zarka’s blog however his script would not work if the user was not licensed. So I modified his script to check if the user was or was not licensed and then either license them or modify their current license.

The script assumes that you have already installed the Office 365 PowerShell Cmdlets as well as the Sign-In assistant.

                                                                                                                                     
###########################################################
# Bulk Enable Office 365 License Options v2.0
# by Martin Bauer | Catapult Systems
# Credit to Roman Zarka for a good chuck of this.
###########################################################

# — Concept applies to E3 license, but is easily adapted
# — As written, will check if user has license currently and add desired license
# — if they are not licensed it will enable Office license option for existing user(s)
# — Import O365 PowerShell Cmdlets and then get credentials and connect to O365
# — Replace TenantName with your O365 Tenant Name
Import-Module MSOnline
$Cred = Get-Credential  
Connect-MSOLService -Credential $Cred
# — Specify user or import userlist from CSV
#Get-MsolUser -User UserPrincipalName@contoso.com | ForEach {
Import-Csv c:\Temp\AssignLicenseOptions.csv | ForEach {
# — Begin loop though list of UPNs, specify variables and set them to disabled.
$Upn = $_.UserPrincipalName
$Exchange = "Disabled"; $SharePoint = "Disabled"; $Lync = "Disabled"; $Office = "Disabled"; $WebApps = "Disabled"; $RMS = "Disabled"
Write-Host "User UPN: " $UPN
# — Get license provisioning status
(Get-MsolUser -User $Upn).Licenses[0].ServiceStatus | ForEach {
    If ($_.ServicePlan.ServiceName -eq "EXCHANGE_S_ENTERPRISE" -and $_.ProvisioningStatus -ne "Disabled") { $Exchange = "Enabled" }
    If ($_.ServicePlan.ServiceName -eq "SHAREPOINTENTERPRISE" -and $_.ProvisioningStatus -ne "Disabled") { $SharePoint = "Enabled" }
    If ($_.ServicePlan.ServiceName -eq "MCOSTANDARD" -and $_.ProvisioningStatus -ne "Disabled") { $Lync = "Enabled" }
    If ($_.ServicePlan.ServiceName -eq "OFFICESUBSCRIPTION" -and $_.ProvisioningStatus -ne "Disabled") { $Office = "Enabled" }
    If ($_.ServicePlan.ServiceName -eq "SHAREPOINTWAC" -and $_.ProvisioningStatus -ne "Disabled") { $WebApps = "Enabled" }
    }
# — Determine which license is currently configured, comment out which license you would like to enable
    $DisabledOptions = @()
    #If ($Exchange -eq "Disabled") { $DisabledOptions += "EXCHANGE_S_ENTERPRISE" }
    If ($SharePoint -eq "Disabled") { $DisabledOptions += "SHAREPOINTENTERPRISE" }
    If ($Lync -eq "Disabled") { $DisabledOptions += "MCOSTANDARD" }
    If ($Office -eq "Disabled") { $DisabledOptions += "OFFICESUBSCRIPTION" }
    If ($WebApps -eq "Disabled") { $DisabledOptions += "SHAREPOINTWAC" }

 

    $LicenseOptions = New-MsolLicenseOptions -AccountSkuId "TenantName:ENTERPRISEPACK" -DisabledPlans $DisabledOptions
    
    $LicenseStatus = ((Get-MsolUser -User $Upn).isLicensed)
 Write-Host -foregroundcolor yellow "User current license status:"
 Write-host "Office: " $Office
 Write-host "Lync: " $Lync
 Write-host "WebApps: " $WebApps
 Write-host "SharePoint: " $SharePoint
 Write-host "Exchange: " $Exchange
 Write-Host ""

 

    #Write-Host "User is license status:" (Get-MsolUser -User $Upn).isLicensed
    #IF (($Exchange = "Disabled") -AND ($SharePoint = "Disabled") -AND ($Lync = "Disabled") -AND ($Office = "Disabled") -AND ($WebApps = "Disabled") )
    IF ($LicenseStatus -ne "False")
 {
 #Write-Host "License Status: "$LicenseStatus
 Write-Host -foregroundcolor yellow "User has nothing licensed, licensing user with UPN: " $Upn
        Set-MsolUserLicense -UserPrincipalName $UPN -AddLicenses "TenantName:ENTERPRISEPACK" -LicenseOptions (New-MsolLicenseOptions -AccountSkuId "TenantName:ENTERPRISEPACK" -DisabledPlans OFFICESUBSCRIPTION ,MCOSTANDARD, SHAREPOINTWAC, SHAREPOINTENTERPRISE)
 Write-Host ""
    }
    ELSE
    {
 Write-Host -foregroundcolor green "User currently has license."
 Write-Host -foregroundcolor yellow "Licenseing user with UPN: " $Upn
 Write-Host -foregroundcolor yellow "Adding License Options if not already enabled."
 Set-MsolUserLicense -User $Upn -LicenseOptions $LicenseOptions
 Write-Host ""
    }
}

 

 

References:

http://blogs.technet.com/b/zarkatech/archive/2012/12/05/bulk-enable-office-365-license-option.aspx

http://onlinehelp.microsoft.com/en-us/office365-enterprises/hh124998.aspx