Parse PDQ Inventory CLI Output data

Trying to parse data to collect info via code from inventory directly.

Basically from PowerShell I save the output

$compdata = PDQInventory GetComputer $compname


output is formatted like this (I shortened it a bit)

Name : compname
ID : number

Operating System
Name : Microsoft Windows 11 Enterprise Insider Preview
Version : 10.0.22463.1000

Active Directory
Path : AD Path

Manufacturer : Dell Inc.
Model : Model


How do I go about converting this into a format that I can parse through and grab the name or ip like json?

I've tried to pipe ConvertTo-Json but the output I get is not as expected and I can't seem to parse it properly.





Date Votes
  • Unfortunately, that command was never built to be computer parsable. You can try to use -split and Select-String, but it's likely to be error prone. I have a couple of alternatives:

    1. Use an Auto Report to export the data you want to a CSV file.
    2. Install my PowerShell module named PdqStuff, then use Get-PdqInventoryComputerData.
    Install-Module -Name 'PdqStuff'
    Import-Module -Name 'PdqStuff'

    Read the warning, then:

    Get-Help Get-PdqInventoryComputerData -Full
  • Colby Bouma

    Thanks Colby!

    I went through the module but I'm notorious for locking our database up when using anything with a hint of SQL so I ended up using code from here for the time being.


    $computer = "some_computer"

    $computerData = PDQInventory.exe GetComputer -computer $computer

    $computerData | Get-Content -Path C:\output.txt $hashObj = @{} $hashObj2 = @{} $category = "Host" foreach($line in $output){ if($line -cnotmatch ":" -and $line -ne " "){ $category = $line $categoryChanged = $true $hashObj2 = @{} } if($line -cmatch ":"){ $data = $line.Split(":") $key = $($data[0].trim(' ')) $val = $($data[1].trim(' ')) $hashObj2.Add("$key","$val") if(!($hashObj.ContainsKey($category))){ $hashObj.Add("$category",$hashObj2) } else{ $hashObj."$category".Add("$key","$val") } $hashObj2 = @{} } } $jsonObj = $hashObj | convertto-json

    At the end of it I convert back from json and remove the file made before.

    $parseObj = $jsonObj | convertfrom-json

    Remove-Item -Path C:\output.txt

    Then i'm able to parse through the data through the $parseObj variable.




Please sign in to leave a comment.

Didn't find what you were looking for?

New post