Ellen Sellers
Ellen Sellers

Reputation: 191

How to display the license type for each user in office 365 powershell script

I am trying to display the username and primary SMTP address of exported users from Office 365 as well as the license type assigned to each user. The output I am getting shows the username is licensed true and the SMTP email address but is not showing what license is assigned to that user.

This is the script I have so far:

Connect-MsolService
get-msoluser -All | where-object {$_.islicensed -eq "true"} |
Select-Object Displayname,islicensed,
@{n="PrimarySMTP";e={$_.proxyAddresses | Where-Object {$_ -clike "SMTP:*"}}}

Gives me an output of:

SMPO Admin           True            SMTP:[email protected]            
Joe Smith            True            SMTP:[email protected]                
Kevin Smith          True            SMTP:[email protected]                     
Monica Smith         True            SMTP:[email protected]    

where I would to display

Monica Smith         True            SMTP:[email protected]      EXCHANGE ONLINE PLAN 1  
SMPO Admin           True            SMTP:[email protected]       ENTERPRISE PACK     
Joe Smith            True            SMTP:[email protected]         ENTERPRISE PACK      
Kevin Smith          True            SMTP:[email protected]       ENTERPRISE PACK

Upvotes: 0

Views: 1417

Answers (1)

Robert Dyjas
Robert Dyjas

Reputation: 5217

You need to use LicenseAssignmentDetails property. For example, to generate space-separated list of licenses you can use:

| Select-Object Displayname,islicensed,
@{n="PrimarySMTP";e={$_.proxyAddresses | Where {$_ -clike "SMTP:*"}}},
@{n="Licenses";e={$_.LicenseAssignmentDetails.AccountSku.SkuPartNumber -join " "}}

The result would be:

DisplayName       IsLicensed PrimarySMTP                    Licenses
-----------       ---------- -----------                    --------
FirstName LastName      True SMTP:[email protected]          SPE_E5 MCOPSTNC MCOPSTN_5 FLOW_FREE POWERAPPS_VIRAL POWER_BI_STANDARD

Upvotes: 1

Related Questions