Quantcast
Channel: PowerShell
Viewing all articles
Browse latest Browse all 136

Unable to run Power shell scripts inside asp.net mvc-5 web application deployed under IIS-8

$
0
0

I am working on an asp.net MVC-5 web application which is deployed under IIS8. Inside my web application i have the following method which will run some power cli scripts and save the returned results inside our Database :-

 var shell = PowerShell.Create();
                        var shell2 = PowerShell.Create();
                        var shell3 = PowerShell.Create();

                        string PsCmd = "add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '" + vCenterName + "';$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;

                        //Powercli script to the the hypervisor network info
                        string PsCmd2 = "add-pssnapin VMware.VimAutomation.Core; $vCenterServer = '" + vCenterName + "';$vCenterAdmin = '" + vCenterUsername + "' ;$vCenterPassword = '" + vCenterPassword + "';" + System.Environment.NewLine;



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



                        PsCmd2 = PsCmd2 + " Get-VMHost " + vCenterName + "| Get-VMHostNetworkAdapter -VMKernel" + System.Environment.NewLine;



                        shell.Commands.AddScript(PsCmd);
                        shell2.Commands.AddScript(PsCmd2);

                        dynamic results = shell.Invoke(); // execute the first powercli script
                        dynamic results2 = shell2.Invoke();//execute the second powercli script

                        if (results != null && results.Count > 0 && results[0].BaseObject != null) // the powercli executed successfully

now when i deploy this web application on our test server which is (Windows Server 2008 R2 + IIS-7) the application will run the above code without any problems.

But on our production environment the method will fail to run the powershell scripts and the powershell results will be null. now on production we have (Windows Server 2012 R2+ IIS-8) unlike our test server which is (Windows Server 2008 +IIS7).

Finally I already did these setting inside the production environment:-

  1. I define a domain user inside the DefaultAppPool:-

enter image description here

  1. i add the above domain user to the local administration group inside the host machine:-

enter image description here

  1. i enable anonymous authentication and i define the IUSR as follow, i also try changing this to "Application Pool Identity" but will not work also:-

enter image description here

Final note when i tried to manually run the above scripts directly inside the powercli window on the production environments, the scripts will work well...

so can anyone advice what is causing the powershell scripts to stop working inside my asp.net mvc web application which is deployed under IIS-8 ?

Thanks


Viewing all articles
Browse latest Browse all 136

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>