Running powershell from cmd line with many parameters

Within powershell this works, but I need it to launch from a command/cmd startup environment:

powershell -f c:\folder\create-something.ps1 -var1 "my test" -var2 "testing" -var3 @(import-csv c:\some folder\file.csv) -endDate 6/1/2015

How can I get this working?
LVL 67
sirbountyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
That won't work with -File, because you want to import in the command line itself. Any specific reason you're not passing the path and then importing in the script?
Anyway, the command line would have to look like that (note the use of double and single quotes):
powershell.exe -Command "& 'c:\folder\create-something.ps1' -var1 'my test' -var2 'testing' -var3 @(Import-Csv 'c:\some folder\file.csv') -endDate 6/1/2015"

Open in new window

If you're restricted to double quotes, the quotes inside the command would need to be escaped with backslashes.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
oBdA, are you sure about the backslashes? This depends on the calling program; cmd.exe requires a caret ^, but doubling the quotes should also work.
0
oBdACommented:
Tested it on a command prompt.
Learned the hard way that the backslash escapes the quote when wondering for quite some time why a simple
robocopy "C:\Source\" "D:\Target\"
threw errors about the arguments ...
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Robocopy is different, this is not the default behaviour. But yes, RoboCopy uses backslash for escaping.
0
oBdACommented:
That's not robocopy specific. xcopy.exe and echoargs.exe (part of PowerShell Community Extensions, https://pscx.codeplex.com/releases) exhibit the same behavior, for example.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.