Parse PDQ Inventory CLI Output data



  • Colby Bouma

    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
    Comment actions Permalink
  • Lavar Lawrence

    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.



    Comment actions Permalink

Please sign in to leave a comment.