Forum Discussion
PowerShell to update License features
I'm not sure if you managed to solve this, but I wrote a couple powershell functions that might help. I wasn't having a good time trying to re-assign licenses to users as we don't enable all features of a license. I found it easier to just remove all the licenses and re-assign them. that way I knew exactly which licenses they had.
The first is a function to clear the license for the user and the second function clears the licenses and then assigns the specific licenses, with the options that we chose. I hope it helps!
# Removes all O365 Licenses
# Accepts UPN
# Returns Nothing
function Remove-O365Licenses ($upn)
{
# Get user info from O365
$userInfo = Get-MsolUser -UserPrincipalName $upn
# Clear any existing licenses
if ($userInfo.isLicensed -eq $true)
{
foreach ($sku in ($userInfo | select -ExpandProperty licenses))
{
#Write-Host "Removing License: " $sku.AccountSkuId
Set-MsolUserLicense -UserPrincipalName $upn -RemoveLicenses $sku.AccountSkuId
}
}
}
# Clears previous license and sets correct Office 365 Staff license
# Accepts UPN
# Returns nothing
function Set-O365StaffLicense ($upn)
{
# Set SKU options for staff
$O365SkuStaff1 = New-MSOLLicenseOptions -AccountSkuID "lethsd51:PROJECTONLINE_PLAN_1_FACULTY" -DisabledPlans SHAREPOINTWAC_EDU
$O365SkuStaff2 = New-MSOLLicenseOptions -AccountSkuID "lethsd51:STANDARDWOFFPACK_FACULTY" -DisabledPlans EXCHANGE_S_STANDARD,SHAREPOINTSTANDARD_EDU
$O365SkuStaff3 = New-MSOLLicenseOptions -AccountSkuID "lethsd51:OFFICESUBSCRIPTION_FACULTY" -DisabledPlans SWAY,SHAREPOINTWAC_EDU
# Get user info from O365
$userInfo = Get-MsolUser -UserPrincipalName $upn
Write-Host "Processing $upn"
# Set usage location
if ($userInfo.UsageLocation -eq $null)
{
Set-MsolUser -UserPrincipalName $upn -UsageLocation CA
}
# Remove All Current Licenses
Remove-O365Licenses ($upn)
# Apply licenses. The order of these matter!
Write-Host "Setting License: Project Online for Faculty"
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses lethsd51:PROJECTONLINE_PLAN_1_FACULTY -LicenseOptions $O365SkuStaff1
Write-Host "Setting License: Office 365 Education for Faculty"
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses lethsd51:STANDARDWOFFPACK_FACULTY -LicenseOptions $O365SkuStaff2
Write-Host "Setting License: Office 365 ProPlus for Faculty"
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses lethsd51:OFFICESUBSCRIPTION_FACULTY -LicenseOptions $O365SkuStaff3
Write-Host "Setting License: Exchange Online Plan 2 for Faculty"
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses lethsd51:EXCHANGEENTERPRISE_FACULTY
}