I am trying to pull substrings out of text files in bulk saving these substrings to an array. I have tried variations of the following. This outputs all of the selected strings to the screen but only saves the final output to the variable. Is there a way to mimic the functionality of a =+ operator in outvariable so that all items get stored in an array?
$FILES = ls "*.txt"
foreach($f in $FILES){
$in=Get-Content $f
$in | Foreach { Select-String -Path "$f" -Pattern "Ad ID" -outvariable
array1 }}
In the event that my strategy is misguided, the overall purpose of pulling substrings into an array is to have several arrays of separate substrings of these text files. Then I will concatenate the values into a csv. I'm attempting to pull elements out rather than re-arrange the text files as substrings within the text files are in different order. Example:
Txt File One:
Ad Id: xxxx
Ad Text: blah blah
Ad placement: spaceship
Txt File Two:
Ad Id: yyyy
Ad placement: zoo
Ad Text: blah blah
Final desired result (this part is working except for the order of the elements)
CSV file
xxxx, spaceship, blah blah
yyyy, zoo, blah blah