Running powershell scripts from ASP.NET

Hi,

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?
LVL 1
ukkaapieAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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 Specialist/DeveloperCommented:
Under what account is you AppPool running?
0
CoralonCommented:
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.

Coralon
0
Dan McFaddenSystems EngineerCommented:
This is do-able as per the example C# WinForm article below states... should be similar for ASP.NET.

Links:
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.

Dan
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

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.
0
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.

Dan
0

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:
Dan...

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

Excellent... all working great now...

Shane
0
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
Powershell

From novice to tech pro — start learning today.