I have an *.exe that outputs this data when I run this PowerShell command:
& $myExe list
Where $myExe
is something like C:\Temp\MyExe.exe
and list
is an argument.
List of Runbook ID on the system:
List of services installed on the system:
ALMService Version: 7.0.4542.16189
AOSService Version: 7.0.4542.16189
BIService Version: 7.0.4542.16189
DevToolsService Version: 7.0.4542.16189
DIXFService Version: 7.0.4542.16189
MROneBox Version: 7.1.1541.3036
PayrollTaxModule Version: 7.1.1541.3036
PerfSDK Version: 7.0.4542.16189
ReportingService Version: 7.0.4542.16189
RetailCloudPos Version: 7.1.1541.3036
RetailHQConfiguration Version: 7.1.1541.3036
RetailSDK Version: 7.1.1541.3036
RetailSelfService Version: 7.1.1541.3036
RetailServer Version: 7.1.1541.3036
RetailStorefront Version: 7.1.1541.3036
SCMSelfService Version: 7.1.1541.3036
The data I'm looking for is the first column of the table, but it has things like List of Runbook ID...
at the top. Is there a good way in PowerShell to parse this data so I can get just the table data?
You could save the output in a variable, use Where-Object
to filter just the lines that have Version
in it, then remove all the unwanted characters with a -replace
regex.
$myExeOutput = & $myExe list
$myExeOutput |
Where-Object {$_ -match 'Version:'} |
ForEach-Object {
$_ -replace '\s+Version:.*$',''
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With