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
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.
###########################################################
# — 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)
$Cred = Get-Credential
Connect-MSOLService -Credential $Cred
#Get-MsolUser -User UserPrincipalName@contoso.com | ForEach {
Import-Csv c:\Temp\AssignLicenseOptions.csv | ForEach {
$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" }
}
$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" }
$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 ""
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