Hey everyone! I've been trying to write a script to remove M365 licenses for a few days now, but I keep running into an error with the 'assignlicense' command. I'm really stuck and could use some help. If anyone has insights or suggestions, I'd love to hear them. Thanks! 🙂
4 Answers
You can simplify things by using Graph commands. For instance, you could run: `$License = Get-MgUserLicenseDetail -UserId ` and then `$result = Set-MgUserLicense -UserId -AddLicenses @() -RemoveLicenses $License.skuid`. Just make sure your Graph PowerShell version is up-to-date to avoid errors!
It would help if you shared what you've tried so far. Also, this article has a lot of commands for removing licenses with PowerShell: [Microsoft Documentation](https://learn.microsoft.com/en-us/microsoft-365/enterprise/remove-licenses-from-user-accounts-with-microsoft-365-powershell?view=o365-worldwide). If you provide the full error message, we might pinpoint the issue faster!
Make sure you're using the latest version of MS Graph PowerShell (2.29.0), as there was a bug that caused issues. Once you upgrade, you can use a script for license management that handles several actions. Check it out here: [O365 Reports](https://o365reports.com/2022/09/08/manage-365-licenses-using-ms-graph-powershell/).
I highly recommend using AD groups for license assignments. It really streamlines the process of adding and removing licenses when you need to provision or deprovision users. Saves you a ton of manual work!
Related Questions
File Hash Generator Online – Get Instant MD5 and SHA-256 Hashes
Visual CSS Editor for Modern Glass UI Effects
Glassmorphism CSS Generator with Live Preview
Online Hash Generator - String to Hash Converter
Convert CSV To HTML Table
Convert Json To Xml