I would probably use the -file argument, as in
-file "C:\PowershellScripts\script.ps1"
you may need to set the execution policy first if it's not already set to unrestricted on your system.
On my machine, a Windows 7 64-bit box with 64-bit Eclipse and a 64-bit jdk (1.6), I am able to get things to work if I set the "arguments" field to:
-executionpolicy unrestricted -file "c:\code\test.ps1"
An alternative that also worked for me was:
Set the application to launch as C:\Windows\System32\cmd.exe
Set the arguments field to something like:
/c "powershell -executionpolicy unrestricted -file c:\code\test.ps1"
That does seem excessively Rube Goldbergian to me, but it's worth a try to see if your problems can be worked around by using a normal shell.
I did briefly get symptoms similar to what you describe, but I can't reproduce them anymore.
- Launch Windows PowerShell, and wait a moment for the
PS
command prompt to appear
Navigate to the directory where the script lives
PS> cd C:\my_path\yada_yada\ (enter)
Execute the script:
PS> .\run_import_script.ps1 (enter)
What am I missing??
Or: you can run the PowerShell script from cmd.exe
like this:
powershell -noexit "& ""C:\my_path\yada_yada\run_import_script.ps1""" (enter)
according to this blog post here
Or you could even run your PowerShell script from your C# application :-)
Asynchronously execute PowerShell scripts from your C# application
Best Answer
Are you sure it's an execution policy error? If it's PowerShell v2, try including the
-File
parameter before the file name: