The enclosing "
characters in "$string1"
have syntactic function and are therefore stripped during parsing.
To make such characters a part of the data, you must embed escaped versions of them (`"
):
PS> "`"$string1`"" # assume that $string1 contains verbatim: foo
"foo"
`
is PowerShell's general escape character; in the context of "..."
strings (expandable strings) you can use `"
and ""
interchangeably.
Also note that the command above relies on PowerShell's implicit output feature - no need for Write-Host
, unless you explicitly want to write to the display only, without PowerShell's rich output formatting - see this answer for more information.