Here’s a great one liner I use all the time to run a report get our user’s O365 licenses.
This should go without saying, but make sure you’ve installed the MSOnline module. Then connect with Connect-MSOLService.
Get-MSOLuser -All | Where-Object {$_.licenses -ne $null} | Select-Object UserPrincipalname, @{Name='Licenses'; Expression={$_.licenses.accountskuid}}
You should get an output similar to this:

You could add a Export-Csv or Convertto-JSON | Out-file .\filename.json if you wanted to have a report you wanted to send off or plug into another piece of software respectively.
By day, I’m a systems admin for a medium size company in the Pacific Northwest.
By night, I’m a blogger, gamer, and all around general nerd.
If you found one of my articles useful, please consider supporting this site!
Monero: 48PxwMvbwoB2M86sHespLBKcSL9cWxrnJDmga9XshSqRP1joykRNpKkDGUz4ohhxD1bMH92poMyZWBBqkPmQ2bHpLP4EDnz
Bitcoin: bc1qc0fyze8x9lxp42x5p3zpry6f0lsr6l5pgq4jkh
Ethereum: 0xc613cBc79Ea4a84AE5538ec3321E214363305121