Windows Vista Forums

Script from command-line

  1. #1


    Don Jones [MVP] Guest

    Script from command-line

    Ok... I feel as if this worked for me before.

    From Cmd.exe:

    powershell "c:\test test\test.ps1"



    doesn't work. It tells me it doesn't know what "c:\test" is - implying that
    it's trying to parse the space and ignoring the quotes. Works if the path
    doesn't contain spaces. It's Friday, it's late, and I'm considering an
    insanity plea.

    How do you make this work?

    --
    Don Jones
    Windows PowerShell MVP
    Founder: www.ScriptingAnswers.com
    Co-Author: "Windows PowerShell: TFM"



      My System SpecsSystem Spec

  2. #2


    Keith Hill [MVP] Guest

    Re: Script from command-line

    "Don Jones [MVP]" <don@xxxxxx> wrote in message
    news:3DC9E17E-88D0-4565-BD8C-0870E56AD38E@xxxxxx

    > Ok... I feel as if this worked for me before.
    >
    > From Cmd.exe:
    >
    > powershell "c:\test test\test.ps1"
    >
    > doesn't work. It tells me it doesn't know what "c:\test" is - implying
    > that it's trying to parse the space and ignoring the quotes. Works if the
    > path doesn't contain spaces. It's Friday, it's late, and I'm considering
    > an insanity plea.
    >
    > How do you make this work?
    Hi Don,

    Use the -command argument on PowerShell:

    powershell -command "C:\test test\test.ps1"

    --
    Keith


      My System SpecsSystem Spec

  3. #3


    Shay Levi Guest

    Re: Script from command-line

    Not working in my case

    PS C:\WINDOWS> powershell -command "C:\test test\test.ps1"
    The term 'C:\test' is not recognized as a cmdlet, function, operable program,
    or script file. Verify the term and try again.
    At line:1 char:8
    + C:\test <<<< test\test.ps1


    Shay
    http://scriptolog.blogspot.com



    > "Don Jones [MVP]" <don@xxxxxx> wrote in message
    > news:3DC9E17E-88D0-4565-BD8C-0870E56AD38E@xxxxxx
    >

    >> Ok... I feel as if this worked for me before.
    >>
    >> From Cmd.exe:
    >>
    >> powershell "c:\test test\test.ps1"
    >>
    >> doesn't work. It tells me it doesn't know what "c:\test" is -
    >> implying that it's trying to parse the space and ignoring the quotes.
    >> Works if the path doesn't contain spaces. It's Friday, it's late, and
    >> I'm considering an insanity plea.
    >>
    >> How do you make this work?
    >>
    > Hi Don,
    >
    > Use the -command argument on PowerShell:
    >
    > powershell -command "C:\test test\test.ps1"
    >
    > --
    > Keith


      My System SpecsSystem Spec

  4. #4


    Shay Levi Guest

    Re: Script from command-line

    PS C:\WINDOWS> powershell -command "& {test-path 'C:\test test\test.ps1'}"
    True
    PS C:\WINDOWS> powershell -command "& {'C:\test test\test.ps1'}"
    C:\test test\test.ps1


    Shay
    http://scriptolog.blogspot.com



    > Not working in my case
    >
    > PS C:\WINDOWS> powershell -command "C:\test test\test.ps1"
    > The term 'C:\test' is not recognized as a cmdlet, function, operable
    > program,
    > or script file. Verify the term and try again.
    > At line:1 char:8
    > + C:\test <<<< test\test.ps1
    > Shay
    > http://scriptolog.blogspot.com

    >> "Don Jones [MVP]" <don@xxxxxx> wrote in message
    >> news:3DC9E17E-88D0-4565-BD8C-0870E56AD38E@xxxxxx
    >>

    >>> Ok... I feel as if this worked for me before.
    >>>
    >>> From Cmd.exe:
    >>>
    >>> powershell "c:\test test\test.ps1"
    >>>
    >>> doesn't work. It tells me it doesn't know what "c:\test" is -
    >>> implying that it's trying to parse the space and ignoring the
    >>> quotes. Works if the path doesn't contain spaces. It's Friday, it's
    >>> late, and I'm considering an insanity plea.
    >>>
    >>> How do you make this work?
    >>>
    >> Hi Don,
    >>
    >> Use the -command argument on PowerShell:
    >>
    >> powershell -command "C:\test test\test.ps1"
    >>
    >> --
    >> Keith


      My System SpecsSystem Spec

  5. #5


    Shay Levi Guest

    Re: Script from command-line

    This one is working, test.ps1 contains just "hello"

    PS C:\WINDOWS> powershell -command "& {& 'C:\test test\test.ps1'}"
    hello


    Shay
    http://scriptolog.blogspot.com



    > PS C:\WINDOWS> powershell -command "& {test-path 'C:\test
    > test\test.ps1'}"
    > True
    > PS C:\WINDOWS> powershell -command "& {'C:\test test\test.ps1'}"
    > C:\test test\test.ps1
    > Shay
    > http://scriptolog.blogspot.com

    >> Not working in my case
    >>
    >> PS C:\WINDOWS> powershell -command "C:\test test\test.ps1"
    >> The term 'C:\test' is not recognized as a cmdlet, function, operable
    >> program,
    >> or script file. Verify the term and try again.
    >> At line:1 char:8
    >> + C:\test <<<< test\test.ps1
    >> Shay
    >> http://scriptolog.blogspot.com

    >>> "Don Jones [MVP]" <don@xxxxxx> wrote in message
    >>> news:3DC9E17E-88D0-4565-BD8C-0870E56AD38E@xxxxxx
    >>>
    >>>> Ok... I feel as if this worked for me before.
    >>>>
    >>>> From Cmd.exe:
    >>>>
    >>>> powershell "c:\test test\test.ps1"
    >>>>
    >>>> doesn't work. It tells me it doesn't know what "c:\test" is -
    >>>> implying that it's trying to parse the space and ignoring the
    >>>> quotes. Works if the path doesn't contain spaces. It's Friday, it's
    >>>> late, and I'm considering an insanity plea.
    >>>>
    >>>> How do you make this work?
    >>>>
    >>> Hi Don,
    >>>
    >>> Use the -command argument on PowerShell:
    >>>
    >>> powershell -command "C:\test test\test.ps1"
    >>>
    >>> --
    >>> Keith


      My System SpecsSystem Spec

  6. #6


    Keith Hill [MVP] Guest

    Re: Script from command-line

    "Shay Levi" <no@xxxxxx> wrote in message
    news:8766a94462c68c9ba5b9e1990f2@xxxxxx

    > Not working in my case
    >
    > PS C:\WINDOWS> powershell -command "C:\test test\test.ps1"
    > The term 'C:\test' is not recognized as a cmdlet, function, operable
    > program, or script file. Verify the term and try again.
    > At line:1 char:8
    > + C:\test <<<< test\test.ps1
    >
    Yeah that little ol' space really throws a monkey wrench in the works. This
    works also:

    powershell -noprofile -command "& 'c:\temp\foo bar\baz.ps1'"

    That is pretty close to what you would have to type at the PoSh prompt -
    just some confusion on the quoting.

    --
    Keith


      My System SpecsSystem Spec

  7. #7


    hecks Guest

    Re: Script from command-line

    On Sep 1, 1:56 am, "Keith Hill [MVP]"
    <r_keith_h...@xxxxxx_no_spam_I> wrote:

    > "Shay Levi" <n...@xxxxxx> wrote in message
    >
    > news:8766a94462c68c9ba5b9e1990f2@xxxxxx
    >

    > > Not working in my case
    >

    > > PS C:\WINDOWS> powershell -command "C:\test test\test.ps1"
    > > The term 'C:\test' is not recognized as a cmdlet, function, operable
    > > program, or script file. Verify the term and try again.
    > > At line:1 char:8
    > > + C:\test <<<< test\test.ps1
    >
    > Yeah that little ol' space really throws a monkey wrench in the works. This
    > works also:
    >
    > powershell -noprofile -command "& 'c:\temp\foo bar\baz.ps1'"
    >
    > That is pretty close to what you would have to type at the PoSh prompt -
    > just some confusion on the quoting.
    >
    > --
    > Keith
    Hmm ...

    ----------script----------
    # baz.ps1 #
    write "hello baz, THAT WORKED"

    ----------------------------

    C:\>powershell -command "c:\temp\'foo bar'\baz.ps1"
    hello baz, THAT WORKED

    C:\>powershell "c:\temp\'foo bar'\baz.ps1"
    hello baz, THAT WORKED

    C:\>powershell 'c:\temp\"foo bar"\baz.ps1'
    c:\temp"foo bar\baz.ps1

    C:\>powershell 'c:\temp\foo bar\baz.ps1'
    c:\temp\foo bar\baz.ps1

    -Hecks


      My System SpecsSystem Spec

  8. #8


    Kiron Guest

    Re: Script from command-line

    You can also just single quote or escape the space:

    powershell "c:\test' 'test\test.ps1"
    powershell "c:\test` test\test.ps1"

    --
    Kiron

      My System SpecsSystem Spec

Script from command-line

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass the name of a PowerShell script as a command line para ge PowerShell 1 04 Sep 2009
noob: PS script fails, but runs from command line deko PowerShell 1 30 Mar 2009
Running a command from inside a script, command line is corrupted Raymond Vought PowerShell 4 24 Feb 2009
Call PS Script with Environment Variable in Path via Command Line bsdz PowerShell 4 04 Jun 2008
Running a Command line script from within powershell. rush PowerShell 7 27 Feb 2008