I have a big txt file with repeating strings. Some strings have numbers in the end, so, I need to output only number to a variable for further use in Write-Host. These numbers can change because the file is a test case report and there is no key = value format inside the file. how to did it? This is the script I am using
$file = Get-ChildItem -Path $reportDir -Include $reportName'.'$fileformat -Recurse | sort-Object LastAccessTime
#$A = Get-Content ($reportDir + $SourceFile)
$report=Get-Content ($file) | Select-String -Pattern "Number of test steps"
$report= ???
write-host "{
`"operation`": `"$environment`",
`"status`": `"OK`",
`"ProjectName`": `"$project`",
`"TestSuit`": `"$testSuite`",
`"TestCase`": `"$testCase`",
`"TestStep`": `"$value`",
`"FailStep`": `"$value`",
`"Coverage`": `"$value`",
}"
Now my output looks this:
Number of test steps 16
{
"msg": "RESULT",
"operation": "Default environment",
"status": "OK",
"ProjectName": "$project",
"TestSuit": "Account",
"TestCase": "AccountCases",
"TestStep": "...",
"FailStep": "AccountCases",
"Coverage": "AccountCases",
}
This is part of my report file, there are lines of numbers from which I need
Overview
Project M2M web API Box
Test suite name Account
Test case name AccountCases
Description
Environment Default environment
Base Metrics
Number of test steps 16
Number of load tests 0
Number of assertions 45
Start Time Thu Dec 02 17:33:58 MSK 2021
End Time Thu Dec 02 17:34:07 MSK 2021
Time Taken 9171 ms
TestStep Count 16
Failed TestStep Count 0
Assertion Count 45
Failed Assertion Count 0
Test Step Results
I need 2 values from a parameter 'Number of test steps' and 'Failed TestStep Count'