Connect to Exchange Online:
Connect-ExchangeOnline
Retrieve Users with Licenses:
Use the Get-MsolUser cmdlet to retrieve a list of all users in your Office 365 organization. Then, use the Select-Object cmdlet to filter the results to only include users with licenses.
Get-MsolUser | Select-Object UserPrincipalName, AssignedLicenses
Export to CSV File:
Get-MsolUser | Select-Object UserPrincipalName, AssignedLicenses | Export-Csv -Path "C:\Users\Public\Office365UsersWithLicenses.csv" -NoTypeInformation