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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun VermaakTechnical SpecialistCommented:
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 McFaddenSystems EngineerCommented:
This is do-able as per the example C# WinForm article below states... should be similar for ASP.NET.


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

 Acronis Global Cyber Summit 2019 in Miami

The Acronis Global Cyber Summit 2019 will be held at the Fontainebleau Miami Beach Resort on October 13–16, 2019, and it promises to be the must-attend event for IT infrastructure managers, CIOs, service providers, value-added resellers, ISVs, and developers.

ukkaapieAuthor Commented:
@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 McFaddenSystems EngineerCommented:
By default, an IIS AppPool does not load the user profile when that account is setup as the AppPool's Identity.

I would setting up the AppPool to load the profile.  In IIS Manager, do the following:

1. Select the AppPool that the website is running under
2. Right click it and select Advanced Settings
3. Under the "Process Model" section, change "Load User Profile" from false to true.
4. For safety purposes, do an IISRESET.
5. Verify functionality.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ukkaapieAuthor Commented:

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

Excellent... all working great now...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.