48 Remove Office 365 E3 license for all users
In the below PowerShell script:-
- Name and save the script as “Set-remove_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.
In case of any hurdle, please Contact Us
Note: –
- Key needs to change at 2 places 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" ################################################ Remove license ############################################### . $E3 = '833ne8dd-b296-42b0-a197-1e91e994b900' foreach ($user in $outputs) { $License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense $License.SkuId = $E3 $LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses $LicensesToAssign.AddLicenses = @() $LicensesToAssign.RemoveLicenses = $License.SkuId Set-AzureADUserLicense -ObjectId $User.ObjectId -AssignedLicenses $LicensesToAssign }