![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Passing parameters to PS script and escaping spaces I have written a PS script which requires two parameters to be passed in: one folder name and one number. If I open a PS console I can execute the script like this: c:\myscript.ps1 "c:\my folder\" 1 I am now trying to run this script from a standard cmd console like this: powershell -command c:\myscript.ps1 "c:\my folder\" 1 However the quotes don't seem to work and the script thinks it is getting 3 parameters passed. How do I launch a script and pass parameters which may include spaces? Out of interest, how would I launch it if the path to the script also contains a space, eg: "c:\my folder\myscript.ps1" "c:\my folder\" 1 |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Passing parameters to PS script and escaping spaces After playing around a bit I found this seems to work: powershell -command "& 'c:\my script.ps1' 'c:\my folder\' 1" Are there any other "better" ways? "James" wrote: > I have written a PS script which requires two parameters to be passed in: one > folder name and one number. If I open a PS console I can execute the script > like this: > > c:\myscript.ps1 "c:\my folder\" 1 > > I am now trying to run this script from a standard cmd console like this: > > powershell -command c:\myscript.ps1 "c:\my folder\" 1 > > However the quotes don't seem to work and the script thinks it is getting 3 > parameters passed. > > How do I launch a script and pass parameters which may include spaces? Out > of interest, how would I launch it if the path to the script also contains a > space, eg: > > "c:\my folder\myscript.ps1" "c:\my folder\" 1 |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Passing parameters to PS script and escaping spaces Try this powershell -noprofile -command c:\tools\scripts\test.ps1 {"c:\my folder\"} 1 "James" <James@discussions.microsoft.com> wrote in message news:C2CB354F-BEC8-460C-9229-DA360642E5CF@microsoft.com... >I have written a PS script which requires two parameters to be passed in: >one > folder name and one number. If I open a PS console I can execute the > script > like this: > > c:\myscript.ps1 "c:\my folder\" 1 > > I am now trying to run this script from a standard cmd console like this: > > powershell -command c:\myscript.ps1 "c:\my folder\" 1 > > However the quotes don't seem to work and the script thinks it is getting > 3 > parameters passed. > > How do I launch a script and pass parameters which may include spaces? > Out > of interest, how would I launch it if the path to the script also contains > a > space, eg: > > "c:\my folder\myscript.ps1" "c:\my folder\" 1 |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Passing parameters to a PS script | PowerShell | |||
| Passing parameters to a cmdlet in a variable | PowerShell | |||
| Hosting PowerShell & passing parameters to script | PowerShell | |||
| passing [switch] parameters | PowerShell | |||
| passing parameters to script (ps1) | PowerShell | |||