Search multiline string and edit it.

by OliAdams at 2013-02-10 05:41:54

This is what is returned when I query backup exec. which is stored in the variable $JobInfo.

JOB ID: {1234-123-1234}
JOB ID: {1234-123-1223}


I am trying to find a way to extract the jobid’s from this output.

Thanks in advance.
by DonJ at 2013-02-10 07:38:53
You’d probably use a regular expression, the -match operator, and the resulting $matches collection. Check out about_regular_expressions in the shell’s help.

If the string format is pretty consistent, you could also do…

foreach ($job in $jobinfo) {
$id = $job.substring(9,13)

Or something similar. Depends on how consistent the format is.
by OliAdams at 2013-02-12 00:44:11
Thanks for the fast reply. I didnt realise at first until I saw Don Jones on the book I am reading at the moment your powershell 3 book is fantastic. I have ordered the Toolmaking book aswell.