![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | execute powershell script from commmand line How can you execute a powershell script from the commandline. I'd like to go to start > run on a computer and be able to launch a powershell script but that doesn't seem possible. It looks like to can only do powershell -command (with the powershell command). I'd like to do powershell powershellscript.ps1 and have it run the script. Is there a way of doing this? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: execute powershell script from commmand line You can pass a script as the -command parameter, like: powershell -command C:\Users\Joel\Documents\WindowsPowerShell\Scripts \Help.ps1 |
My System Specs![]() |
| | #3 (permalink) |
| | Re: execute powershell script from commmand line I would assume I have to be doing something wrong then. I have a script that executes perfectly within the powershell gui, but when I run powershell -command "C:\path to powershell script\powershellscript.ps1" it doesn't execute at all. When you look at the powershell help switches the -command switch doesn't mention you can use the command in that fashion. "Joel (Jaykul) Bennett" wrote: Quote: > You can pass a script as the -command parameter, like: > > powershell -command C:\Users\Joel\Documents\WindowsPowerShell\Scripts > \Help.ps1 > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: execute powershell script from commmand line This is a common mistake that people make. It has to do with how quotes are used in cmd.exe and the fact that you need to pass a quoted path to PowerShell. Also you need to use the call operator as well to execute the script. I suggest you read this blog article: http://poshoholic.com/2007/09/27/inv...-or-start-run/. It describes what you have to do to execute PowerShell scripts from a command prompt when there is a space in the path. -- Kirk Munro [MVP] Poshoholic http://www.poshoholic.com "RG" <RG@xxxxxx> wrote in message news:04958BDF-3BDB-4DEC-B843-81EC5B3803B5@xxxxxx Quote: > I would assume I have to be doing something wrong then. I have a script > that > executes perfectly within the powershell gui, but when I run powershell > -command "C:\path to powershell script\powershellscript.ps1" it doesn't > execute at all. When you look at the powershell help switches > the -command > switch doesn't mention you can use the command in that fashion. > > "Joel (Jaykul) Bennett" wrote: > Quote: >> You can pass a script as the -command parameter, like: >> >> powershell -command C:\Users\Joel\Documents\WindowsPowerShell\Scripts >> \Help.ps1 >> |
My System Specs![]() |
| | #5 (permalink) |
| | Re: execute powershell script from commmand line * RG (Fri, 11 Jan 2008 16:53:01 -0800) Quote: > How can you execute a powershell script from the commandline. I'd > like to go to start > run on a computer and be able to launch a > powershell script but that doesn't seem possible. possible? Quote: > It looks like to can only do powershell -command (with the > powershell command). Quote: > I'd like to do powershell powershellscript.ps1 and have it run the > script. Is there a way of doing this? on a computer and be able to launch a powershell script". That should be an easy one: configure the file assocation[1] so that PowerShell is run with the script as an argument instead of Notepad. Thorsten [1] in Windows Explorer |
My System Specs![]() |
| | #6 (permalink) |
| | Re: execute powershell script from commmand line Configuring ps1 files to run when double-clicked or when run through start-run is not recommended for security reasons. It wasn't simply an accident that this was not included in PowerShell 1.0. That doesn't mean you can't put in the file association to run PowerShell, it just means you should think at least twice about it since PowerShell scripts are very powerful and could wreak havoc if a malicious script was run accidentally through a double-click. -- Kirk Munro [MVP] Poshoholic http://poshoholic.com "Thorsten Kampe" <thorsten@xxxxxx> wrote in message news:MPG.21f2e200851e9b3989943@xxxxxx Quote: > * RG (Fri, 11 Jan 2008 16:53:01 -0800) Quote: >> How can you execute a powershell script from the commandline. I'd >> like to go to start > run on a computer and be able to launch a >> powershell script but that doesn't seem possible. > Why doesn't it seem possible and what have you done to make it > possible? > Quote: >> It looks like to can only do powershell -command (with the >> powershell command). > Again: why "does it look like"? What have you tried? > Quote: >> I'd like to do powershell powershellscript.ps1 and have it run the >> script. Is there a way of doing this? > In the beginning you said differently: "I'd like to go to start > run > on a computer and be able to launch a powershell script". That should > be an easy one: configure the file assocation[1] so that PowerShell is > run with the script as an argument instead of Notepad. > > Thorsten > [1] in Windows Explorer |
My System Specs![]() |
| | #7 (permalink) |
| | Re: execute powershell script from commmand line * Kirk Munro [MVP] (Sat, 12 Jan 2008 10:30:45 -0500) Quote: > Configuring ps1 files to run when double-clicked or when run through > start-run is not recommended for security reasons. It wasn't simply > an accident that this was not included in PowerShell 1.0. That > doesn't mean you can't put in the file association to run > PowerShell, it just means you should think at least twice about it > since PowerShell scripts are very powerful and could wreak havoc if > a malicious script was run accidentally through a double-click. Windows execute PowerShell scripts by double clicking is in my opinion not more dangerous than double clicking batch or Python scripts. Hell, even using Windows Explorer is dangerous if you don't pay attention. Thorsten |
My System Specs![]() |
| | #8 (permalink) |
| | Re: execute powershell script from commmand line Yeah, this one always seemed silly to me: a windows patch to include a new scripting language which has a "safety feature" that the scripts don't run unless you do a ton of extra configuration ... but no matching patch to similarly "secure" the built-in scripting languages (including .reg files) that have known exploits in the wild. ;-) Ah well. -- Joel "Jaykul" Bennett On Jan 12, 10:41 am, Thorsten Kampe <thors...@xxxxxx> wrote: Quote: > * Kirk Munro [MVP] (Sat, 12 Jan 2008 10:30:45 -0500) > Quote: > > Configuring ps1 files to run when double-clicked or when run through > > start-run is not recommended for security reasons. It wasn't simply > > an accident that this was not included in PowerShell 1.0. That > > doesn't mean you can't put in the file association to run > > PowerShell, it just means you should think at least twice about it > > since PowerShell scripts are very powerful and could wreak havoc if > > a malicious script was run accidentally through a double-click. > I could second that. Thinking twice is always recommended but letting > Windows execute PowerShell scripts by double clicking is in my opinion > not more dangerous than double clicking batch or Python scripts. Hell, > even using Windows Explorer is dangerous if you don't pay attention. > > Thorsten |
My System Specs![]() |
| | #9 (permalink) |
| | Re: execute powershell script from commmand line Well a plethora of vbscript virus's sent as email attachments taught MS some caution in this matter ![]() we've been thinking of releasing a free tool that you can associate with PS1 files, where you can allow double click but have certian checks (i.e only certian users can run it this way.. optionally it could pop up a yes/no warning, and it might only run scripts signed with a certian trusted certs. -Karl Thorsten Kampe wrote: Quote: > * Kirk Munro [MVP] (Sat, 12 Jan 2008 10:30:45 -0500) Quote: >> Configuring ps1 files to run when double-clicked or when run through >> start-run is not recommended for security reasons. It wasn't simply >> an accident that this was not included in PowerShell 1.0. That >> doesn't mean you can't put in the file association to run >> PowerShell, it just means you should think at least twice about it >> since PowerShell scripts are very powerful and could wreak havoc if >> a malicious script was run accidentally through a double-click. > I could second that. Thinking twice is always recommended but letting > Windows execute PowerShell scripts by double clicking is in my opinion > not more dangerous than double clicking batch or Python scripts. Hell, > even using Windows Explorer is dangerous if you don't pay attention. > > Thorsten |
My System Specs![]() |
| | #10 (permalink) |
| | Re: execute powershell script from commmand line Well I'm trying to find the usefulness of powershell and it just doesn't seem like it's there yet. For one you can't run the scripts against remote machines. V2 supposedly will have this feature but V2 isn't even in beta yet. So I have to log onto a machine and run the script. What's the point in that? I see no reason to change any of my existing vbscript stuff over to powershell as I would loose a ton of functionality. "Karl Prosser[MVP]" wrote: Quote: > Well a plethora of vbscript virus's sent as email attachments taught MS > some caution in this matter ![]() > > we've been thinking of releasing a free tool that you can associate with > PS1 files, where you can allow double click but have certian checks (i.e > only certian users can run it this way.. optionally it could pop up a > yes/no warning, and it might only run scripts signed with a certian > trusted certs. > > -Karl > > Thorsten Kampe wrote: Quote: > > * Kirk Munro [MVP] (Sat, 12 Jan 2008 10:30:45 -0500) Quote: > >> Configuring ps1 files to run when double-clicked or when run through > >> start-run is not recommended for security reasons. It wasn't simply > >> an accident that this was not included in PowerShell 1.0. That > >> doesn't mean you can't put in the file association to run > >> PowerShell, it just means you should think at least twice about it > >> since PowerShell scripts are very powerful and could wreak havoc if > >> a malicious script was run accidentally through a double-click. > > I could second that. Thinking twice is always recommended but letting > > Windows execute PowerShell scripts by double clicking is in my opinion > > not more dangerous than double clicking batch or Python scripts. Hell, > > even using Windows Explorer is dangerous if you don't pay attention. > > > > Thorsten |
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 script to execute simultaneously instead of sequentially | PowerShell | |||
| Execute a powershell script from a webpage | PowerShell | |||
| Execute command line switches from vbs | VB Script | |||
| Running a Command line script from within powershell. | PowerShell | |||