user1763180
user1763180

Reputation: 115

Running PowerShell Script From A Batch File Using C#

i have a powershell script file, and a bat file, the bat file runs the script, so when i double click
the bat file the script get executed.
in my code i do the following:

 ProcessStartInfo info = new ProcessStartInfo(@batchfilename + ".bat");  
            Process processToStart = new Process();  
            processToStart.StartInfo = info;  
            processToStart.Start();  

the batch gets executed and the powershell scripts starts, but it crashes telling me somthing about policy issue.
allthoug my policy is unrestrected, any ideas?

Upvotes: 0

Views: 2205

Answers (2)

Tilak
Tilak

Reputation: 30718

You need to set Execution Policy to unrestricted MSDN.

Execution Policies (From the above MSDN link)

  • Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode.
  • AllSigned - Only scripts signed by a trusted publisher can be run.
  • RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
  • Unrestricted - No restrictions; all Windows PowerShell scripts can be run.

For 64 bit system, it needs to be set separately for x86, and x64.

PowerShell 32 and 64 bit have different execution policy settings

Upvotes: 3

Alexandr Sulimov
Alexandr Sulimov

Reputation: 1924

powershell.exe c:\FULL_PATH\send.ps1

Upvotes: 0

Related Questions