One approach would be to use the .Net class, System.Text.RegularExpressions.Regex
:
$value = "Starting test: Connectivity
Starting test: CheckSecurityError
Starting test: DFSREvent"
$regex = [System.Text.RegularExpressions.Regex]::new('Starting test: (?<testName>.+)')
$regex.Matches($value) | %{$_.Groups['testName'].value}
#or by calling the static method rather than instantiating a regex object:
#[System.Text.RegularExpressions.Regex]::Matches($value, 'Starting test: (?<testName>.+)') | %{$_.Groups['testName'].value}
Output
Connectivity
CheckSecurityError
DFSREvent
Or you can use Select-String
as mentioned in other answers / only using %{$_.Groups['testName'].value
to pull back the relevant capture groups' values from your matches.
$value |
select-string -Pattern 'Starting test: (?<testName>.+)' -AllMatches |
% Matches |
%{$_.Groups['testName'].value}