PowerTip: Escape Parsed Content in PowerShell String


Summary: Use the backtick character to insert data normally parsed by Windows PowerShell in a string.

Hey, Scripting Guy! Question Certain characters (such as the colon and double quotation marks) are special in Windows PowerShell.
           How can I use those in a parsed string?

Hey, Scripting Guy! Answer Use the backtick character (usually under the tilde, and it’s also ASCII character 96), for example:

$OSDrive=’C’

$DriveLetter=”$OSDrive`:”

Comments (2)

  1. Jack says:

    Just a reminder — if a backtick is desired, use two:
    >> write-host "“"
    `

  2. @Jack

    Good point! Thanks for Sharing!

    Cheers!
    Sean

Skip to main content