Powershell via ASP.Net - "The '=' operator failed: Access is denied."
I'm attempting to run Powershell scripts through a web interface coded in C#/ASP.Net. I'm leaving my .ps1 scripts intact and calling them through Process.Start(Powershell);.
The error I receive every time is "The '=' operator failed: Access is denied."开发者_StackOverflow The powershell script portion that fails is on "$LC = Get-Credential" - assignment works everywhere else. Note: This only fails when running through published .aspx on IIS7 webserver. It works correctly when debugging through Visual Studio 2010.
Thanks!
Get-Credential produces a pop up - that will not work from an app pool.
Actually the "Access is Denied" here is the IIS user attempting to start a process. True, you won't be able to Get-Credential (because there's no host to ask for the credentials), but, even if you hardcode a credential, you won't be able to start the process.
In most remote contexts, this priv is turned off.
If you want, you could actually make the web application run under an account that actually can launch processes, but, in reading the first paragraph of your question, I can see you're making a mountain out of a molehill:
I'm attempting to run Powershell scripts through a web interface coded in C#/ASP.Net. I'm leaving my .ps1 scripts intact and calling them through Process.Start(Powershell);.
While this might seem easy, it is most definately the hard way (because it pushes you toward this obscure part of the OS - remote execution privs)
If you're running PowerShell in ASP.NET, you should directly use the [PowerShell] API (See MSDN ) to embed PowerShell in .NET. If you want impersonation to work, you'll also need to follow the instructions in this answer to setup your Runspace.
Hope this Helps
精彩评论