Passing arguments to a powershell script

Topics: Errors, Examples
Thu at 10:05 AM
Hey, I want to run powershell.exe to run a script. But the script in turn takes arguments. How do I achieve this ?

this doesnt work...
myTask.Actions.Add("powershell.exe","C:\\Users\\aqeel\\Desktop\\FYP\\sender.ps1", MyStringArgs);
Coordinator
Thu at 5:32 PM
I've used this format in the past with success:
myTask.Actions.Add("powershell.exe", $"-NoLogo -NonInteractive -WindowStyle Hidden -File \"{scriptFilePathWithNoQuotes}\" {MyStringArgs}", myWorkingDirectory);
Note that if MyStringArgs contains paths that need quotes, you should supply them in the MyStringArgs variable.
var MyStringArgs = "arg1 \"arg2 has spaces\"";
Marked as answer by dahall on 2/16/2017 at 9:32 AM