1

In windows CMD, I want to run a powershell script and pass string params, which have quotes and ampersands in the params.

U:\Desktop>PowerShell .\post "http://domain/api/app?pLanguage=en-US\"&\"pCompanyID=816" "{\"Message\":\"test message - please ignore\"}"
The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

'\"pCompanyID=816"' is not recognized as an internal or external command,
operable program or batch file.

How can I fix this issue?

omega
  • 40,311
  • 81
  • 251
  • 474
  • To start with you should use `PowerShell -Command ""`. In between those doublequotes, enter the command line you'd normally enter at a powershell prompt, and we'll take it from there! – Compo Aug 28 '19 at 21:00
  • Try to [escape](https://ss64.com/nt/syntax-esc.html) the `&` like `^&`... – aschipfl Aug 28 '19 at 21:03

1 Answers1

1

From another question on this site - How to escape ampersands, semicolons, and curly braces in command-line powershell params?

Wrap your command line strings in nested double and single quotes - e.g. "'[somestring]'".

In your specific case:

C:> powershell .\post "'http://domain/api/app?pLanguage=en-US&pCompanyID=816'" "'{\"Message\":\"test message - please ignore\"}'"
mclayton
  • 8,025
  • 2
  • 21
  • 26