Reputation: 465
I am trying to read values from below ping results, like I want to read Received value as 4 or Lost value as 0 using regular expression.
Ping statistics for 74.125.200.94:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 63ms, Maximum = 64ms, Average = 63ms
I am trying with below but no go, Any help?
$test = ping google.co.in
$test -match "^Average = \((\d+)\)$"
Upvotes: 1
Views: 600
Reputation: 59011
Just use [regex]::Match
to grab the information:
$test = ping google.co.in
$match = [regex]::Match($test, 'Received = (\d+), Lost = (\d+)')
$received = $match.Groups[1].Value
$lost = $match.Groups[2].Value
Upvotes: 1