-1
Get-Process -Name "chrome" | Format-Table Name,ID, StartTime, PagedMemorySize | ConvertTo-Csv | Add-Content -Path c:\Out\demo12.csv 
Get-Process -Name "chrome" | Format-Table Name,ID, StartTime, PagedMemorySize | ConvertTo-Json | Set-Content -Path c:\Out\demo12.json
Get-Process -Name "chrome" | Format-Table Name,ID, StartTime, PagedMemorySize | ConvertTo-Xml | Set-Content -Path c:\Out\demo12.xml

WARNING: Resulting JSON is truncated as serialization has exceeded the set depth of 2.
Daniel
  • 4,792
  • 2
  • 7
  • 20
Lytor
  • 1
  • 2
  • What is your question? – Theo Jan 21 '23 at 07:45
  • ```Format-Table``` is for formatting data for *display* purposes (e.g. console / log output). You probably want ```Select-Object``` instead to create *data* suitable for the ```ConvertTo-*``` cmdlets. – mclayton Jan 21 '23 at 08:02
  • Write a script to get list of process (ex. All chrome process) and put Name, Id, StartTime, PagedMemorySize in CSV/XML/JSON/YAML files where possible. – Lytor Jan 21 '23 at 18:07

1 Answers1

0

The ConvertTo-Json cmdlet has a maximum -Depth that:

Specifies how many levels of contained objects are included in the JSON representation. The value can be any number from 0 to 100. The default value is 2. ConvertTo-Json emits a warning if the number of levels in an input object exceeds this number.

So you just need to set this parameter accodingly to the data that you are trying to save. I would also bear in mind what @mclayton said in his comment to your question about not using Format-Table in this case.

Monticola Explorator
  • 1,188
  • 13
  • 20
  • Can these three lines be combined? – Lytor Jan 21 '23 at 18:07
  • Probably they can be combined into one, but I don't know how. Personaly, I would get the data on one sentence and then convert and store it with another three. `$chromeData=Get-Process -Name "chrome" | Format-Table Name,ID, StartTime, PagedMemorySize; $chromeData | ConvertTo-Csv | Add-Content -Path c:\Out\demo12.csv; $chromeData | ConvertTo-Json -Depth 15 | Set-Content -Path c:\Out\demo12.json; $chromeData | ConvertTo-Xml | Set-Content -Path c:\Out\demo12.xml;` – Monticola Explorator Jan 22 '23 at 09:36