ryan-jan / MSCatalog

PowerShell module for searching and downloading offline updates from https://www.catalog.update.microsoft.com
MIT License
66 stars 17 forks source link

Output is cut in PS 5.1 #5

Closed komsorg closed 4 years ago

komsorg commented 4 years ago

Output is cut if executing Get-MSCatalogUpdate in PowerShell 5.1 running on Windows Server 2008 R2. Saved output by using "< %PathToOutputfile.txt%" after cmdlet is the same. Cut output

ryan-jan commented 4 years ago

I believe this is just the default way that PS 5.1 formats the table given that the Title field contains some long values. For example if you use the following does it improve?

Get-MSCatalogUpdate -Search 'asmedia' -AllPages | Format-Table -AutoSize

Failing that you could use Format-List instead.

Get-MSCatalogUpdate -Search 'asmedia' -AllPages | Format-List

EDITED:

I have now been able to test this for myself and it is indeed just the way that PS handles tables with large fields. My suggestion of using the -AutoSize switch has not helped in my testing. However, the option of piping to Format-List produces the best format in my opinion. There is another option with Format-Table which is to specify a subset of the properties that you are interested in. For example:

Get-MSCatalogUpdate -Search 'asmedia' -AllPages | Format-Table -Property Title, Classification, LastUpdated, Size

This should limit the fields displayed and ensure that they all fit in the PS window nicely.

Hopefully that helps and I will close this issue now.

komsorg commented 4 years ago

Format-List parameter allows to fully display all property values, but it's output format is not handy for further data processing. image

Manually extended screen buffer width size in PS Console window settings. image

When I tried to use proposed Format-Table -AutoSize option without hardcoding properties I got only Title, Products, Classification, LastUpdated, Size columns (Guid and other were absent) in output.

Finally I hardcoded properties, so the following command helped to archive the desired result: Get-MSCatalogUpdate -Search "asmedia" -AllPages | Format-Table -AutoSize -Property Title, Products, Classification, Lastupdated, Version, Size, Guid image image

@ryan-jan Would you mind adding special parameter for exporting parsed data to .csv/.json file?

ryan-jan commented 4 years ago

I think you are misunderstanding the issue here. The Get-MSCatalogUpdate command simply returns the updates as a list of PSCustomObjects. The display is handled by PowerShell's built in formatting engine. The only reason the table is not displaying very nicely is because the title field contains very long names. For example, if I make my PowerShell console window really narrow and run the Get-Process command, you can see that long process names are replaced with ... as they fall off the screen width. This is normal behaviour.

Annotation 2020-06-02 171840

If you want to store the output as CSV or JSON you can do it already using PowerShell native commands. For example:

Get-MSCatalogUpdate -Search 'asmedia' | Export-Csv -Path .\test.csv -NoClobber -NoTypeInformation

or

Get-MSCatalogUpdate -Search 'asmedia' | ConvertTo-Json | Set-Content -Path .\test.json