license export in Office365

Frequent Contributor

Hi Experts

please help me with the below two syntaxes

1. i have one office 365 user ,i want to know what license is assigned to this office365 user from Exchange Online powershell module.

2. i have 100 users in csv file, i want to import this csv file and know what are the licenses assigned to these users.

Below is csv file format.


5 Replies
Get started with this examples:
I might have to review them when I get home though

Get-MsolUser -UserPrincipalName | ft DisplayName,Licenses

$csv = Import-Csv c:\your.csv
| ForEach ($user in $csv) {Get-MsoluserLicense} | ft displayname,Licenses | export-csv C:\logfile.csv

Hi when i use the below syntax i am getting output

Get-MsolUser -UserPrincipalName | Format-List DisplayName,Licenses
DisplayName : User1
I tried the below two syntaxes i am getting error

$CSV = Import-CSV C:\userlist.csv
$CSV | ForEach-Object {
$UPN =$_.upn
Get-MsolUser -UserPrincipalName "$UPN" | Format-List DisplayName,Licenses}
$Users= Import-CSV C:\userlist.csv
Foreach($User in $Users){(Get-MsolUser -UserPrincipalName $User.Name).Licenses.DisplayName|Ft} | Export-CSV "C:\output.csv" -NoTypeInformation
my csv file is in the format

There is bracket error in the last one! I’ll check a little later

The below syntax works perfectly fine

$Users= Import-CSV C:\userslist.csv
Foreach($User in $Users){Get-MsolUser -UserPrincipalName $User.Name | Select DisplayName,Licenses}

When i want to export the output to csv file i am not getting the output, i have used the below syntax

Foreach($User in $Users){Get-MsolUser -UserPrincipalName $User.Name | Select DisplayName,Licenses| Export-CSV C:\out.csv -NoTypeInformation}

I am getting output as
user1 System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]
user2       System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]