0

I am trying to run a powershell script(script is used to updated a excel sheet data) in .net web api project as mantioned bellow,

 var ps1File = @"C:\ActiveLKTel.ps1";
 var startInfo = new ProcessStartInfo()
 {
      FileName = "powershell.exe",
      Arguments = $"-NoProfile -ExecutionPolicy unrestricted \"{ps1File}\"",
      UseShellExecute = false
 };
 Process.Start(startInfo);

This works fine when I run .net web api project in localhost, but this does not work when I deploy the .net web api project in IIS

Can someone tell me how to resolve this problem?

1 Answer 1

1

You should use the -File parameter.

var ps1File = @"C:\ActiveLKTel.ps1";
var startInfo = new ProcessStartInfo()
{
     FileName = "powershell.exe",
     Arguments = $"-NoProfile -ExecutionPolicy unrestricted -File \"{ps1File}\"",
     UseShellExecute = false
};
Process.Start(startInfo);

When you run the script in IIS, it is not working because the script will run under the context of the user on the IIS app pool. Does this account have permission to:

  • Run the script
  • Carry out the actions within the script
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.