Hello @Tomass Pētersons , thank you for reaching out. You can use the following PSCmdlets to fetch the list of users and check their license state and which licenses are assigned to them.
Connect-MsolService
Get-MsolUser | Select DisplayName, UserPrincipalname, IsLicensed, Licenses
If you want to export the result in a .csv file just use the following cmdlet:
Connect-MsolService
$path = "C:\temp\NoLicenseUsersList.csv"
Get-MsolUser | Select DisplayName, UserPrincipalname, IsLicensed, Licenses | Export-Csv -Path $path -NoTypeInformation -Append
Hope this helps.
Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as an Answer; if the above response helped in answering your query.