O365 License Discovery and Management
If you’ve ever had the pleasure of working with the built-in O365 cmdlets for viewing and modifying licenses you’ve probably come across:
Set-MsolUserLicense : Unable to assign this license because it is invalid. Use the Get-MsolAccountSku cmdlet to retrieve a list of valid licenses.
In every instance I ran across this “error” it was because the license I was attempting to set was already active for the account. Instead of a notice that no changes have been made, like we had with on-prem Exchange, you get complete misdirection about the root cause. I made a Powershell module to help identify that condition along with providing console feedback. Each cmdlet can stand on it’s own assuming you provide a properly formatted UPN and are connected to MSOnline.
Currently Add-365License and Remove-365License don’t return any values because the O365 account validation happening within the cmdlet along with the actual task of adding/removing a license means there could be two points of failure. If you separate the O365 account validation from the cmdlets I found you lose some flexibility when it comes to live account changes. To each their own, mod away, throw some return true|false if ya get the urge.