Link to home
Start Free TrialLog in
Avatar of ARM2009
ARM2009Flag for United States of America

asked on

Output from Powershell is truncating output - need to autosize width to see all the data

running script to reconsile licenses in O365 and the output is getting truncated.

script is below

Get-MsolUser -All | select displayname, licenses | Format-Table -autosize | Out-File c:\licensed-users.csv

since a user has multiple licenses, that field is getting truncated.

used the following but it also wraps up to a second line, hard to import in excel

Get-MsolUser -All | select displayname, licenses | FT Displayname, Licenses -Wrap | Out-File c:\licensed-users.csv

Is there a way to specify width of column so it does not truncate output?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ARM2009

ASKER

Get-MsolUser -All | Select-Object DisplayName, Licenses | Export-Csv -Path c:\licensed-users.csv -NoTypeInformation

this does not give the right information for licenses

shows license as "System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]"

instead of

{Tenant:ENTERPRISEWITHSCAL}    

with -Wrap the result is as follows ... goes to 2 lines.

{Tenant:RIGHTSMANAGEMENT, Tenant:ENTERPRISEWITHSCAL, Te
                                                            nant:PROJECTONLINE_PLAN_2}
Avatar of ARM2009

ASKER

the second option works well.. lists them in one line without truncating.
Avatar of ARM2009

ASKER

just rechecked the output.... its not truncating but not listing the license name properly... basically repeats the same name.

user that had 2 different license, listed as below

Microsoft.Online.Administration.UserLicense, Microsoft.Online.Administration.UserLicense

so no way to differentiate
Avatar of oBdA
oBdA

Sorry, can't test the original command; try this:
Get-MsolUser -All | Select-Object DisplayName, @{Name="Licenses"; Expression={($_.Licenses | Out-String -Stream) -join ", "}} | Export-Csv -Path c:\licensed-users.csv -NoTypeInformation

Open in new window

Avatar of ARM2009

ASKER

result is as follows

"USER-Display NAME",", ExtensionData                 AccountSku                    AccountSkuId                  ServiceStatus                , -------------                 ----------                    ------------                  -------------                , System.Runtime.Serializati... Microsoft.Online.Administr... TENANT:RIGHTSMANAGEMENT     {Microsoft.Online.Administ..., System.Runtime.Serializati... Microsoft.Online.Administr... TENANT:ENTERPRISEWITHSCAL   {Microsoft.Online.Administ..., System.Runtime.Serializati... Microsoft.Online.Administr... TENANT:PROJECTONLINE_PLAN_2 {Microsoft.Online.Administ..., , "

all in one line.... as you can see this user has 3 licenses, seems like the license are listed in full, the truncated part can be deleted at import.

easier way to do this without post cleanup?
Seems like you're looking for the AccountSkuId?
Get-MsolUser -All | Select-Object DisplayName, @{Name="Licenses"; Expression={($_.Licenses | Select-Object -ExpandProperty AccountSkuId) -join ", "}} | Export-Csv -Path c:\licensed-users.csv -NoTypeInformation

Open in new window

Avatar of ARM2009

ASKER

Thanks! that worked,