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?
ARM2009Asked:
Who is Participating?
 
oBdACommented:
If you're importing the file into Excel anyway, there's no need for Format-Table; just use Export-Csv:
Get-MsolUser -All | Select-Object DisplayName, Licenses | Export-Csv -Path c:\licensed-users.csv -NoTypeInformation

Open in new window

If the Licenses property is an array, you might want something like this to concatenate the licenses properly:
Get-MsolUser -All | Select-Object DisplayName, @{Name="Licenses"; Expression={$_.Licenses -join ", "}} | Export-Csv -Path c:\licensed-users.csv -NoTypeInformation

Open in new window

0
 
ARM2009Author Commented:
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}
0
 
ARM2009Author Commented:
the second option works well.. lists them in one line without truncating.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
ARM2009Author Commented:
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
0
 
oBdACommented:
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

0
 
ARM2009Author Commented:
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?
0
 
oBdACommented:
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

0
 
ARM2009Author Commented:
Thanks! that worked,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.