I would like to capture the value from different regexs in order to build a file list of my endpoint health checks.
I have some PS Script that parses and pull information from some txt file correctly, but I want to use the values captured in the different regexs within my script to compose new strings.
My script below read from txt file #1 and output txt file #2, all correctly.
PS Script
(Get-Content 'c:\fake_path\test_stack.txt') `
| Select-String '(^\S{5}SERVER:)(\S*)(\S{5})','(^\S*n:\"\*:)(\d*)(:"\s$)','(^\"\/)(\S*)("\s$)' -AllMatches | Foreach-Object {$_.Matches} |
Foreach-Object {$_.Groups[2].Value} |
Out-File c:\fake_path\demo_stack.txt
1 InFile
*****SERVER:WIN001*****
SITE.NAME:"PRJ_ABC"
bindingInformation:"*:80:"
"/App001"
*****SERVER:WIN002*****
SITE.NAME:"PRJ_DEF"
bindingInformation:"*:81:"
"/App001"
SITE.NAME:"PRJ_HIJ"
bindingInformation:"*:82:"
"/App001" `
2 OutFile
WIN001
80
App001
WIN002
81
App001
82
App001`
However I'm hoping to use the values that are captured in my 3 different regexs below into 3 different variables, let's say $a, $b and $c.
(Select-String '(^\S{5}SERVER:)(\S*)(\S{5})','(^\S*n:\"\*:)(\d*)(:"\s$)','(^\"\/)(\S*)("\s$)')
My try:
Foreach-Object 'http://' + 'a.{$_.Groups[2].Value}' + ':' + '$b.{$_.Groups[2].Value}' + '/' + '$c.{$_.Groups[2].Value}' + '/api/status'
Desired output of my try (written above)
A new file composed like this:
http://WIN001:80/App001/api/status
http://WIN002:81/App001/api/status
http://WIN002:81/App001/api/status
So as you can see I wanted to capture the regex in variables $a $b and $c, then concatenate strings like http:// + $a + ':' + $b + ..... and so for, in order to format it and produce a url.
I believe this is feasible, just lacking the background.
Welcome all the advices, cheers ;-)