Files
Scripting/Powershell/PowerShell-Office365Admin/MSOnline/BulkReplaceLicence.ps1
DistractADD cfddd4fad2 Added Files
2021-07-06 13:16:46 +10:00

22 lines
657 B
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Bulk replace a licence for all users who have the one being replaced.
#
# What licence are we removing?
$licenceToRemove = ''
# What licence are we adding?
$licenceToAdd = ''
# Import MSOnline module and connect
Import-Module MSOnline
Connect-MsolService
# Find everyone who has the licence being replaced
$users = Get-MsolUser -All | Where-Object {($_.licenses).AccountSkuId -match $licenceToRemove}
# Remove the old licence and add the new one
foreach ($user in $users) {
Set-MSOLUserLicense user $user.UserPrincipalName RemoveLicenses $licenceToRemove
Set-MSOLUserLicense user $user.UserPrincipalName -AddLicenses $licenceToAdd
}