Execute a Powershell file from ASP C # without exhausting / using the IIS memory


I have a Powershell file ps1 that I need to run from a webapp hosted on IIS created in ASP C #; the Powershell file is on the server where the app lives, when I run it manually from the server, it works well and it gives me the expected results, but when it is executed from the app on another machine it does not seem to have the performance that it would seem that executes the "fast" powershell file in such a way that it does not allow you to read the output of the commands.

My code in c # is a web service that executes the powershell file, here the fragment where it is executed:

    var shell = PowerShell.Create();

AS AN EXAMPLE: This is a fragment of the code in powershell:

$ServiceInfo = Get-WmiObject -Class Win32_Service -ComputerName "NOMBRESERVER" | Where-Object { $_.Name -eq "Dhcp"} | Select Name, DisplayName, State
    Write-Output "Servicio encontrado"
    Write-Output "Servicio NO encontrado"

Executed from the server, finds the information without problem, it does it well.

Executed from the webapp always shows "Service NOT found" as if you did not wait for the results of the Get-WmiObject


I have the assumption that the IIS has something to do with regards to permissions or memory.

Additionally my powershell code is inside a block:

Start-Job -ScriptBlock {  }

For the process to run in "Background"

asked by Ricardo Soria 15.11.2018 в 20:18

0 answers