In my PowerShell script, I\'m running Select-String over a number of files, looking for a string passed into it via a variable ($id):
foreach ($file in (ls \
Use the static escape()
method, it instructs the regular expression engine to interpret these characters literally rather than as metacharacters:
$id = [regex]::escape($id)
You can also turn the command to a one liner (-path
can take a collection of files):
Select-String -Path path\to\files\\* -Pattern ([regex]::escape($id)) -Quiet