$items - an arbitrarily named variable
= - sign signifying equality
Get-ChildItemThus $items now equals an array of files in the current folder that match *.txt
$items[0] = firstfile.txt
$items[1] = secondfile.txt
etc
etc
etc
$items.Count - total number of matching files found
for(){} - a
for loop, $i is a variable that gets incremented by 1 every loop until the total number of matching files is reached
Thus loop through all the files in the array performing the following on every file:
Select-String -Path $items[$i] -Pattern $regex -AllMatchesSearch each file for matching RegEx pattern, get all matches.
| % { $_.Matches } | % { $_.Value } >> $outfileRegEx matches are piped into a
ForEach-Object loop, (shorthand notation). For each regex match, pipe it's value to the output file in append mode.
Don't actually need to escape the " in the RegEx either:
$regex = '<dsf:tsdfgd trsdfge="urn:x-ssdfgs-dfg-com:isdfgc/tg4r3e-i4d" id="OsdfgsdfD">'
Will also work.
Same as the 6 lines
above without assigned variables or a for loop:
gci *.txt
| % { sls
$_.Name
-Pattern '<dsf:tsdfgd trsdfge="urn:x-ssdfgs-dfg-com:isdfgc/tg4r3e-i4d" id="OsdfgsdfD">' -a
| % { $_.Matches
} | % { $_.Value
} >> K:\out.txt
}