Souladin
asked on
Parsing Select-String pattern matches
(This is a follow up to the question that I posted here)
While the regex works great, this is the first time I've worked with pulling matches from a text file this way (normally I get CSV or Excel files) and I'm getting lost parsing through them all and storing the values into variables. For reference, here is an example of what is in each text file being queried:
Here is the test script I'm using to parse through one file.
Where I'm getting lost is how to get the various values that are in the .Matches.Groups into the $personID, $fullName, and $emailAddress variables. Or am I going about parsing $fileContent all wrong?
While the regex works great, this is the first time I've worked with pulling matches from a text file this way (normally I get CSV or Excel files) and I'm getting lost parsing through them all and storing the values into variables. For reference, here is an example of what is in each text file being queried:
<option value="1992560">LASTNAME, FIRSTNAME - [firstname.lastname@domain.com]</option>
<option value="1934672">TEST, TESTTODAY - [testtoday@domain.com]</option>
<option value="1912146">TEST, TEST1 - [test1234@gmail.com]</option>
<option value="1900934">TEST, TEST2 - [ctest119@test.com]</option>
<option value="1900933">TEST, TEST3 - [ctest117@test.com]</option>
<option value="1958349">TEST, RTO - [generic100@domain.com]</option>
Here is the test script I'm using to parse through one file.
$filePath = "\\SERVER01\NetShare\IT\Infrastructure\Desktop\Audit\UserLists\env\Beta.txt"
$regex = "<option value=""(\d*)"">([\w ]*), ([\w ]*)- [(.*)@(.*)]"
$fileContent = Select-String -Path $filePath -Pattern $regex -AllMatches
ForEach ($groups in $fileContent.Matches) {
ForEach ($group in $groups.Groups) {
$personID
$fullName
$emailAddress
$SQLQuery = "INSERT INTO [#env$envName] VALUES ('$personID','$fullName','$emailAddress')"
Write-Output $SQLQuery
}
}
Where I'm getting lost is how to get the various values that are in the .Matches.Groups into the $personID, $fullName, and $emailAddress variables. Or am I going about parsing $fileContent all wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER