Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of oBdA
oBdA

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 ...
Robocopy is different, this is not the default behaviour. But yes, RoboCopy uses backslash for escaping.
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.