Quick tip: PowerShell here-strings don’t like whitespace

Today I was writing a bit of raw XML to be used as a SOAP message. Being a person who enjoys writing easy to read code, I declared my variable using here-string notation, pasted in the appropriate XML between the @” and “@, making sure to indent everything along the way including the last “@.

Then when I saved my work and tried to run the script, I kept getting an error claiming the “@ terminator was missing. Fast forward a couple minutes of head scratching, checking, double-checking , and triple-checking that there was, indeed, a double-quote followed by an at symbol. Finally I figured it out. The here-string’s “@ terminator needs to be on its own line, with no preceding white-space/tabs/whatever.

And there we have it: my forehead-slapping moment, transformed into a helpful PowerShell quick tip. ๐Ÿ™‚


  1. JDMils says:

    Thanks! That was the exact same situation- head scratching and couldn’t figger it out until I saw your post.

  2. SreekanthCHAVA says:

    Thanks a lot it saved a lot of time , simple thing but most important. I browsed thought lot of sites but no one spelled this point.

    Thanks a lot

  3. Thanks!

  4. Sunit Joshi says:

    I can’t get it to work. Each time I enter it, I get this #*#*# error !

    PS C:\Windows\SysWOW64\WindowsPowerShell\v1.0> $chunk=@”
    The string is missing the terminator: “.
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

  5. Thanks dude, this helped me alot with my script!

  6. Thanks mate, you saved me a lot of time by sharing this with community !!


  1. fashion online shopping free shipping worldwide

    Quick tip: PowerShell here-strings don’t like whitespace โ€” DAMIAN KARLSON

Speak Your Mind