Better way to parse choco command outputs
regg00 opened this issue · comments
Is your feature request related to a problem? Please describe.
Not a problem, but a significant improvement.
The way choco outputs are parsed right now is too basic.
Describe the solution you'd like
The matching should be done more specifically using regex queries with the Select-String
command.
Describe alternatives you've considered
$CommandOutput.RawOutput -like "*$n *already installed.*"
Additional context
Given the following output:
Installing the following packages:
rufus
By installing, you accept licenses for the packages.
rufus v4.2.0 [Approved]
rufus package files install completed. Performing other installation steps.
ShimGen has successfully created a shim for rufus.exe
The install of rufus was successful.
Software installed to 'C:\ProgramData\chocolatey\lib\rufus'
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
We can extract the Name, Version and Status with those commands:
$Name = ($test | Select-String '^rufus$').matches[0].value
$Version = ($test | Select-String 'v\d.\d.\d').matches[0].value
$Installed = $test | Select-String '^ The install of rufus was successful.$' -Quiet
I ended up using -match
for conditional checks instead of -like
or Select-String
.