49 Add Microsoft 365 E3 License to all users with Office 365 E3 license
In the below PowerShell script:-
- Name and save the script as “Set-add_office365_license.PS1”.
- Create a folder at drive C with folder temp (C:\temp).
- Replace the bold red key with your o365 key that you would like to remove.
- Run the script now and the output will be saved as CSV form into the “C:\PS\O365\Migration” path.
Note: –
- Key needs to change at 1 place in the script.
In case of any hurdle, please Contact Us
$E3 = '833ne8dd-b296-42b0-a197-1e91e994b900'
$outputs = Get-AzureADUser -Top 9000 | where {$_.AssignedLicenses.skuid -like "*$E3*" }
$outputs.count
$outputs | sort UserPrincipalName| select MailNickName,UserPrincipalName, UsageLocation | Export-Csv -NoTypeInformation "C:\PS\O365\Migration\AllUsersE3_$((get-date).toString('yyyy-MM-dd_hh-mm-ss')).csv"
$outputsM3 = Get-AzureADUser -Top 9000 | where {$_.AssignedLicenses.skuid -like "*$($M3.skuid)*" }
$outputsM3.count
$outputsM3 | sort UserPrincipalName| select MailNickName,UserPrincipalName, UsageLocation | Export-Csv -NoTypeInformation "C:\PS\O365\Migration\AllUsersM3_$((get-date).toString('yyyy-MM-dd_hh-mm-ss')).csv"
############################################### add licenses #####################################################
$M3 = Get-AzureADSubscribedSku | ? {$_.skuPartnumber -eq 'SPE_E3' }
foreach ($user in $outputs)
{
#$username = "testaduser"
#$email = $username + "@infotechfusionwordpress.com"
$user.UserPrincipalName
Set-AzureADUser -ObjectId $User.ObjectId -UsageLocation $user.UsageLocation
$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = $M3.skuid
#$License.DisabledPlans = $DisabledPlans
$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$LicensesToAssign.AddLicenses = $License
$LicensesToAssign.RemoveLicenses = @()
Set-AzureADUserLicense -ObjectId $User.ObjectId -AssignedLicenses $LicensesToAssign
}