0

We have hosted an application which access the powershell script from C# code. It is running perfectly on localhost. But when we hosted that application script is running with the service account rather user account.

We've enabled windows authentication in application, but the Powershell command is running with service account which is used as IIS Application pool.

Thanks in Advance!!

  • Welcome to StackOverflow. We all enjoy helping folks, but there are rules to follow in order for folks to assist: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) - [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) - [Why is "Can someone help me?" not an actual question?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-actual-question). – postanote May 04 '20 at 23:20
  • Running PowerShell using a service account is a common thing, with lots of articles all over the web. [running powershell with a service account](https://www.bing.com/search?q=running+powershell+with+a+service+account&form=ANNTH1&refig=0a53e1ccf69b4c5c94c14271739f4b33&sp=-1&pq=running+powershell+with+a+service+acco&sc=0-38&qs=n&sk=&cvid=0a53e1ccf69b4c5c94c14271739f4b33) – postanote May 04 '20 at 23:23
  • could you please share your sample code to reproduce the issue? also, share your web.config file. try to set the under section in web.config file. make sure other authentication mode is disabled. – Jalpa Panchal May 05 '20 at 08:00
  • @postanote thanks for your response. We are able to run the powershell using Service account. I don't want to use service account to run the script. I want the logged in user account to run the powershell window with his own credentials. – Koduru Sudheer May 05 '20 at 10:49
  • @JalpaPanchal, we have enabled the windows authentication in our hosted website. But the powershell window is not running with the User account – Koduru Sudheer May 05 '20 at 10:51
  • Restart-Computer -ComputerName "Computer name to be restarted" I want to run this piece of code from the visual studio console application . It's working as expected from the local machine. I've hosted the console application and tried to run the same application. Then whenever I'm running the application, it's taking the service account details and returning failure errors. If someone is browsing the application, this above code should run with their own credentials – Koduru Sudheer May 05 '20 at 11:03
  • you could try to set this core in web.config file: https://stackoverflow.com/questions/20410725/prompt-for-credentials-in-asp-net-c-sharp-page-pass-to-powershell – Jalpa Panchal May 06 '20 at 09:00

0 Answers0