This script was required by a company as they renewed there Microsoft agreement with different levels of O365 Licenses, replacing E1 and EO2 licenses with E3 and EMS. The script is padded out with outputs to the initiator to see what is going on.
Sections are broken down as follows:
- Connect to Microsoft Online with Gloabl Administrator
- Collect information from text file (users email addressed)
- Loop to get each users current license, remove E1 or EO2 and add E3 and EMS whilst informing the Initiator with what task is taking place
- Output users name and new licenses to confirm the script has worked
## ## ## ## ## ## ## ## ## ## ## ## ## ## O365 License Update ## ## Remove E1 and EO2 ## ## Add E3 and EMS Licenses ## ## Ben Prudence - 13/04/2016 ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## Connect to MSOL Connect-MsolService -ea Stop ## Import user list (Email Address Per Line) $users = Get-Content "C:\Scripts\e3change.txt" ## Check E1 and EO2 Licenses, if used then remove them ## Add E3 and EMS License foreach ($user in $users){ $CheckE1 = Get-MSOLUser -UserPrincipalName $User | Select UserPrincipalName, {$_.Licenses.AccountSkuId} | ? {$_.Licenses.AccountSkuId} -eq 'affinitywaterltd:STANDARDPACK' $CheckEO2 = Get-MSOLUser -UserPrincipalName $User | Select UserPrincipalName, {$_.Licenses.AccountSkuId} | ? {$_.Licenses.AccountSkuId} -eq 'affinitywaterltd:EXCHANGEENTERPRISE' $CheckE3 = Get-MSOLUser -UserPrincipalName $User | Select UserPrincipalName, {$_.Licenses.AccountSkuId} | ? {$_.Licenses.AccountSkuId} -eq 'affinitywaterltd:ENTERPRISEPACK' $CheckEMS = Get-MSOLUser -UserPrincipalName $User | Select UserPrincipalName, {$_.Licenses.AccountSkuId} | ? {$_.Licenses.AccountSkuId} -eq 'affinitywaterltd:EMS' if ($CheckE1){ Write-Host $user "Has an E1 License, Now removing" -BackgroundColor Gray -ForegroundColor White Set-MSolUserLicense -userprincipalname $user -RemoveLicenses affinitywaterltd:STANDARDPACK Write-Host $user "E1 License removed" -BackgroundColor Green -ForegroundColor Black } if ($CheckEO2){ Write-Host $user "Has an EO2 License, Now removing" -BackgroundColor Gray -ForegroundColor White Set-MSolUserLicense -userprincipalname $user -RemoveLicenses affinitywaterltd:EXCHANGEENTERPRISE Write-Host $user "EO2 License removed" -BackgroundColor Green -ForegroundColor Black } if ($CheckE3){Write-Host $user "Already an E3 License holder" -BackgroundColor Green -ForegroundColor Black} else{ Write-Host $user "Does not have an E3 License, Now Adding" -BackgroundColor Gray -ForegroundColor White Set-MSolUserLicense -userprincipalname $user -AddLicenses affinitywaterltd:ENTERPRISEPACK Write-Host $user "E3 License Added" -BackgroundColor Green -ForegroundColor Black } if ($CheckEMS){Write-Host $user "Already an EMS License holder" -BackgroundColor Green -ForegroundColor Black} else{ Write-Host $user "Does not have an EMS License, Now Adding" -BackgroundColor Gray -ForegroundColor White Set-MSolUserLicense -userprincipalname $user -AddLicenses affinitywaterltd:EMS Write-Host $user "EMS License Added" -BackgroundColor Green -ForegroundColor Black } } ## Print Users and licenses for confirmation after Script complete foreach ($user in $users){ Get-MSOLUser -UserPrincipalName $User | Select UserPrincipalName, {$_.Licenses.AccountSkuId} }
Leave a Reply