Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Script from command-line

Reply
 
Old 08-31-2007   #1 (permalink)
Don Jones [MVP]


 
 

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
Old 08-31-2007   #2 (permalink)
Keith Hill [MVP]


 
 

Re: Script from command-line

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

> 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
Old 08-31-2007   #3 (permalink)
Shay Levi


 
 

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


Quote:

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

>> 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
Old 08-31-2007   #4 (permalink)
Shay Levi


 
 

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


Quote:

> 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
Quote:

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

>>> 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
Old 08-31-2007   #5 (permalink)
Shay Levi


 
 

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


Quote:

> 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
Quote:

>> 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
Quote:

>>> "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
Old 08-31-2007   #6 (permalink)
Keith Hill [MVP]


 
 

Re: Script from command-line

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

> 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
Old 09-02-2007   #7 (permalink)
hecks


 
 

Re: Script from command-line

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

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

> > Not working in my case
>
Quote:

> > 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
Old 09-03-2007   #8 (permalink)
Kiron


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
How to pass the name of a PowerShell script as a command line para PowerShell
noob: PS script fails, but runs from command line PowerShell
Running a command from inside a script, command line is corrupted PowerShell
Call PS Script with Environment Variable in Path via Command Line PowerShell
Running a Command line script from within powershell. PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46