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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Make Network Traffic Fast and Furious with SD-WAN

Software-defined WAN (SD-WAN) is a technology that determines the most effective way to route traffic to and from datacenter sites. Register for the webinar today to learn how your business can benefit from SD-WAN!

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.