Lazy Diary @ Hatena Blog

PowerShell / Java / miscellaneous things about software development, Tips & Gochas. CC BY-SA 4.0/Apache License 2.0

How to escape special characters in PowerShell

Ways to escape special characters in PowerShell are different between its context, and so complecated...

# Context Escaped char " ' \ ` ``
1 String with " "
2 String with " $
3 String with " '
4 String with " `
5 String with ' "
6 String with ' $
7 String with ' '
8 String with ' `
9 Operand of -like with " *
10 Operand of -like with ' *
11 Operand of -match with " *
12 Operand of -match with ' *
13 Placeholder of -F operator *1 { and }

legend

  • ✓ … You can use it to escape
  • ✘ … You cannot use it to escape
  • - … You don't have to escape