1

I don't think I can use a standard cmdlet for this. I have the following string Backup Job INDETERMINABLE STRING HERE completed successfully

I need to extract the INDETERMINABLE STRING HERE which could be any length and any number of words. The text to the left will always be Backup Job and the text to the right will either be completed successfully OR failed with errors.

How would I go about this?

1 Answer 1

2

Here you go, this makes use of the $matches automatic variable.

$regEx = "Backup Job (.*)(completed successfully|failed with errors)"
$good  = "Backup Job INDETERMINABLE STRING HERE completed successfully"
$bad   = "Backup Job INDETERMINABLE STRING HERE failed with errors"

if ($good -match $regEx)
{
    $matches[1]
}
if ($bad -match $regEx)
{
    $matches[1]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.