Toolvito

Works on this device

Powershell String Escaper

Paste text to get it as a PowerShell string that keeps every character. You can also paste a PowerShell string to see the text it stands for. The work is done on your device and nothing is run.

Your text

Type or paste the text exactly as PowerShell must keep it. It stays on this device and nothing is run.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Enter your text, or choose Try an example.

How to use this tool

  1. Type or paste your text exactly as PowerShell must keep it.
  2. Choose the form of string. If you are not sure, use the single-quoted string: PowerShell changes nothing inside it.
  3. Copy the result into your script or your command.
  4. Check the table What PowerShell reads back. It must show your text.
  5. To check a string that you already have, choose Read a PowerShell string back to plain text in the menu.

The four forms and their rules

Forms of a PowerShell string
Form What PowerShell does inside What must be escaped
Single-quoted string Nothing. Every character is kept. A single quote is written twice.
Double-quoted string A dollar sign starts a variable or an expression. A backtick escapes the next character. A backtick is put before each backtick, dollar sign and double quote.
Single-quoted here-string Nothing. It can have many lines. Nothing can be escaped. A line of the text may not start with a single quote and an at sign.
Double-quoted here-string Variables and backtick escapes work. It can have many lines. Quotes need no escape. A backtick is put before each backtick and dollar sign.

The backtick is the grave accent character, on the key at the top left of many keyboards. It is the escape character of PowerShell. The backslash is a normal character in PowerShell strings.

PowerShell also reads the curly quotes that word processors make as quotes. So a curly single quote inside a single-quoted string is written twice, and a curly double quote inside a double-quoted string gets a backtick.

A here-string starts with an at sign and a quote at the end of a line, and ends with a quote and an at sign at the start of a line. The text stands on the lines between them.

Backtick escapes in double-quoted strings

  • A backtick and the letter n is a line break. With t it is a tab, with r a carriage return, and with 0 a zero character.
  • A backtick and a, b, f or v is the bell, backspace, form feed or vertical tab character.
  • In PowerShell 6 and later, a backtick and e is the Escape character, and a backtick, u and hex digits inside curly brackets is any Unicode character. Windows PowerShell 5.1 does not know these two.
  • A backtick before any other character gives that character. This is how a dollar sign or a quote is kept.

Worked example

The text It's here as a single-quoted string is 'It''s here'. The single quote inside is written twice.

The text Total: $5 "now" as a single-quoted string is 'Total: $5 "now"', with no change inside. As a double-quoted string it needs three backticks: one before the dollar sign and one before each of the two double quotes.

Limits you should know

  • The tool does not run PowerShell. It cannot know the value of a variable, so when you read a string that has a variable in it, the variable is shown as written.
  • When a string is passed as an argument to a program outside PowerShell, such as an .exe file, PowerShell changes it again and the versions differ. Windows PowerShell 5.1 and PowerShell up to 7.2 drop double quotes inside an argument unless each has a backslash before it. PowerShell 7.3 and later pass them on. Test with your own version.
  • The line breaks in a here-string are the line ends of your script file. A file saved on Windows often has two characters at each line end, and a file saved on Linux has one.
  • A string is only one part of a command. Other characters with a special meaning outside strings, such as the semicolon and the pipe sign, are safe inside a quoted string.
  • For the Windows command prompt and batch files use the Windows Command Line Escaper.
  • The text can have up to 100,000 characters.

Related tools