Avatar of ukkaapie
 asked on

Running powershell scripts from ASP.NET


I am trying to run a powershell script from an ASP.NET page.

I have configured the application pool to run under a doman account identity but the powershell script appears to be running under the machine account.

When I add $env:username to the powershell script, it returns computername$

Any ideas where I am going wrong?
PowershellASP.NETMicrosoft IIS Web Server

Avatar of undefined
Last Comment

8/22/2022 - Mon
Shaun Vermaak

Under what account is you AppPool running?

As Shaun is pointing out.. the scripts are going to run in the context of the AppPool that is running the website.  I'm not an IIS expert, (I have some experience with it).. I believe you might be able to request credentials from the user and use those in your powershell scripts.  I'm not sure how or if you could capture any kind of passthrough authentication.

Dan McFadden

This is do-able as per the example C# WinForm article below states... should be similar for ASP.NET.

1. https://blogs.msdn.microsoft.com/zainnab/2008/07/26/calling-a-powershell-script-from-your-net-code/
2. http://jeffmurr.com/blog/?p=142

The important thing to do is use the System.Management.Automation name space instead of calling a command.

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

@Shaun - The application pool is running under a domain account.

@Dan - That namespace is being used to call the script and not a command.
Dan McFadden

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question


Thanks heaps for that.  Completely forgot but I had to do that for a website belonging to someone else.

Excellent... all working great now...