Exporting all Users with specific licenses to CSV

Bühler Gabriel 81 Reputation points
2022-03-03T15:17:02.537+00:00

Hello Everyone

I am trying to export all users with specific licenses into a csv-file. Here is the command I've been trying to use:

Get-MsolUser -all | Select FirstName, LastName, DisplayName, City, Country, PrincipalName, Title, Department, Licenses | Where-Object {($_.Licenses).LicenseAssigned  -match "PROJECTPROFESSIONAL" -or "PROJECTPREMIUM" -or "PROJECTESSENTIALS" -or "POWER_BI_PRO" } | export-csv C:\export5.csv -NoTypeInformation -Encoding UTF8 -Append

Unfortunately the export doesn't give me the licenses, only this entry: System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]

What am I doing wrong? My goals is to see all the details I mentioned plus if they are using the licenses, which of the licenses they are having.

Thank you for your Help.

Kind regards,

Gabriel

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Other
0 comments No comments
{count} vote

3 answers

Sort by: Most helpful
  1. Danilo Crivellaro 6 Reputation points
    2022-07-04T20:13:38.87+00:00

    @Bühler Gabriel

    Try this:

    Get-MsolUser -All |select UserPrincipalName,@{n="Licenses Type";e={$_.Licenses.AccountSKUid}} | Export-CSV c:\temp\users.csv

    1 person found this answer helpful.
    0 comments No comments

  2. Rich Matheisen 47,901 Reputation points
    2022-03-03T20:25:09.497+00:00

    There are many examples of how to do this if look for them. Try searching for something like "powershell export msol users with licenses".

    Here's just one result: export-list-office-365-users-licenses-customer-tenants-delegated-administration

    0 comments No comments

  3. Marilee Turscak-MSFT 37,206 Reputation points Microsoft Employee Moderator
    2022-03-04T18:42:48.583+00:00

    Hi @Bühler Gabriel ,

    You need to search by AccountSkuId.

    Specifying the tenant name:

    Get-MsolUser -UserPrincipalName $audituser | Select-Object -ExpandProperty Licenses | Where-Object {$_.AccountSkuID -eq $TenantName + ':POWER_BI_PRO'}  
    

    The tenant domain name prefixes the SKU:

    Get-MsolUser -all | Select FirstName, LastName, DisplayName, City, Country, PrincipalName, Title, Department, Licenses | Where-Object{ $_.Licenses.AccountSkuId -match "tenantdomainname:PROJECTPREMIUM" }  
    

    Additional examples:

    Users with a specific license

    Automate user license

    Get users with multiple specified licenses

    Project SKU

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.