Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell systeminfo as JSON or XML

I am executing:

   systeminfo | ConvertTo-Json 

   "Host Name:                 namehere",
   "OS Name:                   Microsoft Windows 10 Enterprise",
    ...

but I need

   "Host Name":                 "namehere",
   "OS Name":                   "Microsoft Windows 10 Enterprise",
    ...

The following command gives a similar issue

systeminfo | ConvertTo-Xml -As String

<?xml version="1.0" encoding="utf-8"?>
<Objects>
  <Object Type="System.String"></Object>
  <Object Type="System.String">Host Name:                 namehere</Object>
  <Object Type="System.String">OS Name:                   Microsoft Windows 10 Enterprise</Object> " 

but I need something like:

    <?xml version="1.0" encoding="utf-8"?>
    <HostName>namehere</HostName>
    <OSName>Microsoft Windows 10 Enterprise</OSName> 
    ...
like image 458
Harsha Laxman Avatar asked Oct 17 '25 20:10

Harsha Laxman


1 Answers

try this:

systeminfo /fo CSV | ConvertFrom-Csv

or

systeminfo /fo CSV | ConvertFrom-Csv | convertto-json
like image 183
thom schumacher Avatar answered Oct 20 '25 09:10

thom schumacher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!