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. 🙂

Comments

  1. birkin bag cost in india kolkata 2014 Welcome to InteliGator – Perform Instant Background Checks with InteliGator | – Welcome to InteliGator – Perform Instant Background Checks with InteliGator how to buy an hermes birkin bag 2014 trend
    replique bracelet love cartier prix http://www.bestcbangs.in/

  2. Henrik says:

    Thx! Saved me some headscratching.

  3. JDMils says:

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

  4. 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
    SreekanthCHAVA

  5. Thanks!

  6. 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

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

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

Trackbacks

  1. love it says:

    love it

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

  2. fashion online shopping free shipping worldwide

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

Speak Your Mind

*