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 - Powershell.exe command-line syntax

Reply
 
Old 03-27-2007   #1 (permalink)
EnigmaticSoul


 
 

Powershell.exe command-line syntax

Howdy,

Hoping to try and accomplish something like this:

powershell.exe -command "& {c:\script.ps1; if (!$?) {read-host -
prompt "An error occurred`nPress any key to exit"}}"

but can't seem to get the syntax quite right. Not sure if it will even
work, even once I get the syntax out of the way.

Any thoughts?

Thanks,
Shawn.


My System SpecsSystem Spec
Old 03-28-2007   #2 (permalink)
Keith Hill


 
 

Re: Powershell.exe command-line syntax

"EnigmaticSoul" <sferrier@gmail.com> wrote in message
news:1175050381.667262.15690@n59g2000hsh.googlegroups.com...
> Howdy,
>
> Hoping to try and accomplish something like this:
>
> powershell.exe -command "& {c:\script.ps1; if (!$?) {read-host -
> prompt "An error occurred`nPress any key to exit"}}"


This works for me:

230> powershell.exe -command C:\Users\Keith\bar.ps1;if (!$?) {
Read-host -prompt "Errored occurred`nPress any key" }
doh!
At C:\Users\Keith\bar.ps1:1 char:6
+ throw <<<< "doh!"
Errored occurred
Press any key:

--
Keith

My System SpecsSystem Spec
Old 03-28-2007   #3 (permalink)
EnigmaticSoul


 
 

Re: Powershell.exe command-line syntax

That works for me when I launch it from within powershell - but not
when I'm trying to launch it from cmd.exe. I don't get the read-host
prompt when I launch it from there. Any thoughts as to why this would
behave differently?

Thanks,
Shawn.

On Mar 28, 12:56 am, "Keith Hill" <r_keith_h...@mailhot.nospamIdotcom>
wrote:
> "EnigmaticSoul" <sferr...@gmail.com> wrote in message
>
> news:1175050381.667262.15690@n59g2000hsh.googlegroups.com...
>
> > Howdy,

>
> > Hoping to try and accomplish something like this:

>
> > powershell.exe -command "& {c:\script.ps1; if (!$?) {read-host -
> > prompt "An error occurred`nPress any key to exit"}}"

>
> This works for me:
>
> 230> powershell.exe -command C:\Users\Keith\bar.ps1;if (!$?) {
> Read-host -prompt "Errored occurred`nPress any key" }
> doh!
> At C:\Users\Keith\bar.ps1:1 char:6
> + throw <<<< "doh!"
> Errored occurred
> Press any key:
>
> --
> Keith



My System SpecsSystem Spec
Old 03-28-2007   #4 (permalink)
EnigmaticSoul


 
 

Re: Powershell.exe command-line syntax

Further to this, the following works for me:
powershell -command write-host "test"; c:\test2.ps1

but this does not:
powershell -command c:\test2.ps1; write-host "test"

It's the latter that I need to figure out somehow.

On Mar 28, 2:11 pm, "EnigmaticSoul" <sferr...@gmail.com> wrote:
> That works for me when I launch it from within powershell - but not
> when I'm trying to launch it from cmd.exe. I don't get the read-host
> prompt when I launch it from there. Any thoughts as to why this would
> behave differently?
>
> Thanks,
> Shawn.
>
> On Mar 28, 12:56 am, "Keith Hill" <r_keith_h...@mailhot.nospamIdotcom>
> wrote:
>
> > "EnigmaticSoul" <sferr...@gmail.com> wrote in message

>
> >news:1175050381.667262.15690@n59g2000hsh.googlegroups.com...

>
> > > Howdy,

>
> > > Hoping to try and accomplish something like this:

>
> > > powershell.exe -command "& {c:\script.ps1; if (!$?) {read-host -
> > > prompt "An error occurred`nPress any key to exit"}}"

>
> > This works for me:

>
> > 230> powershell.exe -command C:\Users\Keith\bar.ps1;if (!$?) {
> > Read-host -prompt "Errored occurred`nPress any key" }
> > doh!
> > At C:\Users\Keith\bar.ps1:1 char:6
> > + throw <<<< "doh!"
> > Errored occurred
> > Press any key:

>
> > --
> > Keith



My System SpecsSystem Spec
Old 03-29-2007   #5 (permalink)
Keith Hill


 
 

Re: Powershell.exe command-line syntax

"EnigmaticSoul" <sferrier@gmail.com> wrote in message
news:1175106290.829504.193740@y80g2000hsf.googlegroups.com...
> Further to this, the following works for me:
> powershell -command write-host "test"; c:\test2.ps1
>
> but this does not:
> powershell -command c:\test2.ps1; write-host "test"
>
> It's the latter that I need to figure out somehow.


I was able to get this to work from cmd:

C:\Users\Keith>powershell -command write-host "hi";write-host
"there";read-host
-prompt 'Press any key'
hi
there
Press any key:


Note that I had to use single quotes around the prompt string.

--
Keith

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
PowerShell command line quotation parsing quirk - can it be fixed? PowerShell
Running a Command line script from within powershell. PowerShell
Command line option syntax error. Type /? for Help Vista mail
How to launch the pretty PowerShell command line from VS? 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