简体   繁体   中英

are there any restrictions of runningPowerShell Methods on IIS web application

I want to run PowerCLI scripts inside my asp.net mvc web application. so i have installed the PowerCLI application inside my application server. then i wrote the following test action method, and i run the web application inside my visual studio and everything worked well:-

public ActionResult About(string vCenterIp = "****", string vCenterUsername = "****", string vCenterPassword = "****")
        {


var shell = PowerShell.Create();



                string PsCmd = "add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '" + vCenterIp + "';$vCenterAdmin = '" + vCenterUsername + "' ;$vCenterPassword = '" + vCenterPassword + "';" + System.Environment.NewLine;



                PsCmd = PsCmd + "$VIServer = Connect-VIServer -Server $vCenterServer -User $vCenterAdmin -Password $vCenterPassword;" + System.Environment.NewLine;


                PsCmd = PsCmd + "Get-VMHost" + System.Environment.NewLine;



                shell.Commands.AddScript(PsCmd);

                var results = shell.Invoke();




                if (results.Count > 0)

now my question will i be ale to run the above action method when i deploy my web application to an IIS ? as from my reading seems IIS by defualt does not allow to run EXE scripts .. so are there any restrictions or concerns i need to take case of before deploying my application to an IIS since i am running powerCLI scripts inside it ?

Here's someone else who has attempted what you're doing....

http://jeffmurr.com/blog/?p=142 ...

I love the last bit...

To run this on a server, the ApplicationPool hosting your application will have to have administrator rights.

It really depends on your organization and where you intend to deploy this site. For many businesses, running anything on a web server with admin privileges would be completely unacceptable.

I'd try and avoid this if you can, perhaps have a separate windows service which communicates with the web site using a database as an intermediary, ie the web site sticks a job in the database, the windows service processes it securely, posts the results to SQL Server, the user can view the results on another page which reads the data written.

If that sounds like too much effort, I'd at least use this approach...

Execute PowerShell as an administrator from C#

...to create a site that runs with normal (reduced) privileges and temporarily elevates it's privileges to run the powershell script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM