Remove all O365 Licences with the exception of 1 or 2

So, I have created a Powershell script to remove all O365 licences for a user (automating leavers), however we don’t want to remove the Exchange Online or E3 licences straight away as people may want access to the users inbox.

The part of the script that does this is below:

 (get-MsolUser -UserPrincipalName $upn).licenses.AccountSkuId | foreach{ Set-MsolUserLicense -UserPrincipalName $upn -RemoveLicenses $_ } 

Any ideas on how to filter this so it doesn’t remove certain licences?

Much appreciated.

submitted by /u/mbh9999
[link] [comments]

Leave a Reply