license export in Office365

%3CLINGO-SUB%20id%3D%22lingo-sub-304841%22%20slang%3D%22en-US%22%3Elicense%20export%20in%20Office365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-304841%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Experts%3C%2FP%3E%3CP%3Eplease%20help%20me%20with%20the%20below%20two%20syntaxes%3C%2FP%3E%3CP%3E1.%20i%20have%20one%20office%20365%20user%20user1%40mydomain.com%20%2Ci%20want%20to%20know%20what%20license%20is%20assigned%20to%20this%20office365%20user%20from%20Exchange%20Online%20powershell%20module.%3C%2FP%3E%3CP%3E2.%20i%20have%20100%20users%20in%20csv%20file%2C%20i%20want%20to%20import%20this%20csv%20file%20and%20know%20what%20are%20the%20licenses%20assigned%20to%20these%20users.%3C%2FP%3E%3CP%3EBelow%20is%20csv%20file%20format.%3C%2FP%3E%3CP%3EName%3CBR%20%2F%3Euser1%40mydomain.com%3CBR%20%2F%3Euser2%40mydomain.com%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-304841%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExchange%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%20Groups%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-305681%22%20slang%3D%22en-US%22%3ERe%3A%20license%20export%20in%20Office365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-305681%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EThe%20below%20syntax%20works%20perfectly%20fine%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%24Users%3D%20Import-CSV%20C%3A%5Cuserslist.csv%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EForeach(%24User%20in%20%24Users)%7BGet-MsolUser%20-UserPrincipalName%20%24User.Name%20%7C%20Select%20DisplayName%2CLicenses%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EWhen%20i%20want%20to%20export%20the%20output%20to%20csv%20file%20i%20am%20not%20getting%20the%20output%2C%20i%20have%20used%20the%20below%20syntax%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EForeach(%24User%20in%20%24Users)%7BGet-MsolUser%20-UserPrincipalName%20%24User.Name%20%7C%20Select%20DisplayName%2CLicenses%7C%20Export-CSV%20C%3A%5Cout.csv%20-NoTypeInformation%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EI%20am%20getting%20output%20as%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Euser1%3C%2FSPAN%3E%20%3CSPAN%3ESystem.Collections.Generic.List%601%5BMicrosoft.Online.Administration.UserLicense%5D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3Euser2%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BSystem.Collections.Generic.List%601%5BMicrosoft.Online.Administration.UserLicense%5D%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-305655%22%20slang%3D%22en-US%22%3ERe%3A%20license%20export%20in%20Office365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-305655%22%20slang%3D%22en-US%22%3EThere%20is%20bracket%20error%20in%20the%20last%20one!%20I%E2%80%99ll%20check%20a%20little%20later%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-305654%22%20slang%3D%22en-US%22%3ERe%3A%20license%20export%20in%20Office365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-305654%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20when%20i%20use%20the%20below%20syntax%20i%20am%20getting%20output%3C%2FP%3E%3CP%3EGet-MsolUser%20-UserPrincipalName%20user1%40mydomain.com%20%7C%20Format-List%20DisplayName%2CLicenses%3CBR%20%2F%3EDisplayName%20%3A%20User1%3CBR%20%2F%3ELicenses%20%3A%20EMS%2C%20ENTERPRISEPACK%7D%3CBR%20%2F%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3CBR%20%2F%3EI%20tried%20the%20below%20two%20syntaxes%20i%20am%20getting%20error%3C%2FP%3E%3CP%3E%24CSV%20%3D%20Import-CSV%20C%3A%5Cuserlist.csv%3CBR%20%2F%3E%24CSV%20%7C%20ForEach-Object%20%7B%3CBR%20%2F%3E%24UPN%20%3D%24_.upn%3CBR%20%2F%3EGet-MsolUser%20-UserPrincipalName%20%22%24UPN%22%20%7C%20Format-List%20DisplayName%2CLicenses%7D%3CBR%20%2F%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3CBR%20%2F%3E%24Users%3D%20Import-CSV%20C%3A%5Cuserlist.csv%3CBR%20%2F%3EForeach(%24User%20in%20%24Users)%7B(Get-MsolUser%20-UserPrincipalName%20%24User.Name).Licenses.DisplayName%7CFt%7D%20%7C%20Export-CSV%20%22C%3A%5Coutput.csv%22%20-NoTypeInformation%3CBR%20%2F%3E%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3CBR%20%2F%3Emy%20csv%20file%20is%20in%20the%20format%3CBR%20%2F%3EName%3CBR%20%2F%3Euser1%40mydomain.om%3CBR%20%2F%3Euser2%40mydomain.com%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-304909%22%20slang%3D%22en-US%22%3ERe%3A%20license%20export%20in%20Office365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-304909%22%20slang%3D%22en-US%22%3EGet%20started%20with%20this%20examples%3A%3CBR%20%2F%3EI%20might%20have%20to%20review%20them%20when%20I%20get%20home%20though%3CBR%20%2F%3E%3CBR%20%2F%3EGet-MsolUser%20-UserPrincipalName%20User1%40mydomain.com%20%7C%20ft%20DisplayName%2CLicenses%3CBR%20%2F%3E%3CBR%20%2F%3E%24csv%20%3D%20Import-Csv%20c%3A%5Cyour.csv%3CBR%20%2F%3E%7C%20ForEach%20(%24user%20in%20%24csv)%20%7BGet-MsoluserLicense%7D%20%7C%20ft%20displayname%2CLicenses%20%7C%20export-csv%20C%3A%5Clogfile.csv%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-304852%22%20slang%3D%22en-US%22%3ERe%3A%20license%20export%20in%20Office365%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-304852%22%20slang%3D%22en-US%22%3E1.%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fenterprise%2Fpowershell%2Fview-licenses-and-services-with-office-365-powershell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fenterprise%2Fpowershell%2Fview-licenses-and-services-with-office-365-powershell%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E2.%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.spiceworks.com%2Fhow_to%2F66141-powershell-create-and-license-users-in-bulk-on-office-365%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcommunity.spiceworks.com%2Fhow_to%2F66141-powershell-create-and-license-users-in-bulk-on-office-365%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EBest%2C%20Chris%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

Hi Experts

please help me with the below two syntaxes

1. i have one office 365 user user1@mydomain.com ,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.

Name
user1@mydomain.com
user2@mydomain.com

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

Get-MsolUser -UserPrincipalName User1@mydomain.com | ft DisplayName,Licenses

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

Hi when i use the below syntax i am getting output

Get-MsolUser -UserPrincipalName user1@mydomain.com | Format-List DisplayName,Licenses
DisplayName : User1
Licenses : EMS, ENTERPRISEPACK}
==========================================
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
Name
user1@mydomain.om
user2@mydomain.com

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

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]