none
run powershell script from command line,get error The string is missing the terminator: ". RRS feed

  • Question

  • Hi

    I am stuck for hours to make following run;

    1. inside Powershell, it works

    powershell 

    Start-Process -Verb runas cmd "/k dir c:\" 

    2. try to run the above in one shot

    C:\Users\jxzhao>powershell Start-Process -Verb runas cmd "/k dir c:\"
    The string is missing the terminator: ".
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

    anybody knows how to make it work?

    thanks



    • Edited by jzhao2007 Friday, July 10, 2020 10:20 PM
    Friday, July 10, 2020 10:20 PM

All replies

  • Why would you want to do this?

    Please read the help for the PowerShell command line:

    powershell /?

    Always start by reading the help.  Without any understanding of what a command is or how it works you will get nowhere by guessing.


    \_(ツ)_/

    Friday, July 10, 2020 10:27 PM
    Moderator
  • thank you for your very generic quick reply

    Saturday, July 11, 2020 2:19 AM
  • One thing you will not understand as you are not a Powe4rSHell scripter.  The quoting rules for commands and for PowerShell.

    To get an understanding of that you can  also read this help from PowerShell.

    help about_Quoting_Rules

    When running utility programs it is not necessary to use "Start-Process".  Just call the command directly.

    Example:

    powershell -command "notepad"

    powershell -command "runas ..."


    \_(ツ)_/

    Saturday, July 11, 2020 2:39 AM
    Moderator
  • It works with single quotes.  Cmd (or powershell) will take off the double quotes unless they're backslashed. Or put it in a script.  Or pass -argumentlist as an array.


    powershell Start-Process -Verb runas cmd '/k dir c:\'

    powershell Start-Process -Verb runas cmd \"/k dir c:\\\"

    powershell Start-Process -Verb runas cmd /k,dir,c:\

    • Edited by JS2010 Sunday, July 12, 2020 3:21 PM
    Saturday, July 11, 2020 1:30 PM
  • Hi jzhao2007,

    Prepend a backslash \ to the doubel quotes “ and backslash \ to allow them to be treated as ordinary text.


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, July 13, 2020 9:35 AM