I am trying to parse the output of:
wmic copmutersystem
and
net.exe config workstation
using PowerShell to get an object as Key/Value pair and/or convert it to JSON String.
I know there is a PowerShell equivalent command:
Get-CimInstance -Class Win32_computersystem
But the ask here is to figure out how to use PowerShell to parse a similar output for wmic
CMD line.
CodePudding user response:
Use the Get-CimInstance
and ConvertTo-Json
commandlets:
Get-CimInstance -Class Win32_ComputerSystem | ConvertTo-Json
Edit: Previous revision of this answer used Get-WMIObject
, but that's been deprecated.
CodePudding user response:
Wmic can output csv or xml, but obviously get-wmiobject or get-ciminstance is preferred. You just need to find the class names instead of the aliases. The creator of wmic and powershell is the same.
wmic computersystem list /format:csv | convertfrom-csv | select model
Model
-----
OptiPlex 7490 AIO
List wmic class aliases:
wmic alias list brief
For example:
ComputerSystem Select * from Win32_ComputerSystem
get-ciminstance win32_computersystem