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 \
If the $id string already contains something like TAB when it's passed to you then I'm not aware of a built in method to safely escape it back to "\t". You need to make sure your script is passed the correct string in the first place. I.e. it needs to passed 0x5C74 (\t) not 0x09 (TAB). So the escaping needs to be done when the the search string is first defined.
Regex.Escape will escape TAB -> \t but will also escape any of these characters that have meaning within regular expressions:
\, *, +, ?, |, {, [, (,), ^, $,., #, and white space
e.g. . -> \.