0

The following command successfully runs in PowerShell console, but not in cmd prompt. I'm at a loss for how to translate it.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -Command '&{C:\Foo\MyScript.ps1 -InputPath ''C:\Foo'' -OutputPath ''C:\Foo\output'' -XmlPath ''C:\Foo\input\FrontDoor.xml'' -AssemblyPaths ''C:\Foo\input\file1.dll'',''C:\Foo\input\file2.dll'',''C:\Foo\input\file3.dll'' -Version 3 -Format json}; EXIT $LASTEXITCODE'

When running in cmd prompt, I get the following error.

The string is missing the terminator: '.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

I have tried many things to get it to work, but with no success.

Scott Lin
  • 1,532
  • 1
  • 18
  • 28
  • To help with quoting issues look at `-EncodedCommand` switch. – Matt Feb 13 '18 at 18:57
  • 1
    `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -Command "&{C:\Foo\MyScript.ps1 -InputPath 'C:\Foo' -OutputPath 'C:\Foo\output' -XmlPath 'C:\Foo\input\FrontDoor.xml' -AssemblyPaths 'C:\Foo\input\file1.dll','C:\Foo\input\file2.dll','C:\Foo\input\file3.dll' -Version 3 -Format json}; EXIT $LASTEXITCODE"` – user4003407 Feb 13 '18 at 18:58
  • Why do you need to run it from a cmd.exe prompt? Just run the command you want in PowerShell instead. – Bill_Stewart Feb 13 '18 at 19:33
  • @Bill_Stewart, I don't have that convenience. vsts-task-lib is running the command ultimately on a Windows agent in the cloud. – Scott Lin Feb 13 '18 at 19:36
  • [This answer](https://stackoverflow.com/questions/45760457/how-to-run-a-powershell-script-with-white-spaces-in-path-from-command-line/45762288#45762288) will most likely solve your problem – vrdse Feb 13 '18 at 20:04

1 Answers1

0

@PetSerAl, I don't want to take credit. Your comment was the answer. Thank you.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -NonInteractive -Command "&{C:\Foo\MyScript.ps1 -InputPath 'C:\Foo' -OutputPath 'C:\Foo\output' -XmlPath 'C:\Foo\input\FrontDoor.xml' -AssemblyPaths 'C:\Foo\input\file1.dll','C:\Foo\input\file2.dll','C:\Foo\input\file3.dll' -Version 3 -Format json}; EXIT $LASTEXITCODE"
Scott Lin
  • 1,532
  • 1
  • 18
  • 28
  • The `-File` parameter is easier to use IMO. – Bill_Stewart Feb 13 '18 at 23:01
  • Agreed, but unfortunately since I'm passing an array of strings to the script in one of the parameters, I cannot use `-File`. I searched a long while for how to do it and came up short. Would love to learn how if there's a way. – Scott Lin Feb 14 '18 at 02:35
  • Thinking creatively: You can do this by passing a single string argument with some delimiter and then split the string into an array inside the script. – Bill_Stewart Feb 14 '18 at 14:25