![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||