Search code examples
windowspowershellbatch-filetaskscheduler

Windows Power Shell & Console Windows Host processes will keep running after windows task schduler's task ends


I have windows server 2012 R2 , and i have defined a task inside windows task scheduler, as follow:-

-i create a .ps file, which mainly calls a remote URL:-

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$request = [System.Net.WebRequest]::Create("https://ipAddress/")
$response = $request.GetResponse()
$response.Close()

-then i create a .bat file to call the power-shell script, as follow:-

"%SYSTEMROOT%\system32\windowspowershell\v1.0\powershell.exe" -Command Start-Process "$PSHOME\powershell.exe" -Verb RunAs -ArgumentList "'-NoExit %~dp0\AppPoolActivation.ps1'"

-i define the task to run daily on each 30 minutes for a duration of day.

-the task will be calling the .bat file.

enter image description here enter image description here

now i am facing a problem is that when the task runs successfully, two processes will keep running 1)Windows Power Shell & 2)Console Windows host. which will cause my server to became very slow and will stop responding after around 12 hours,, now here is how my task manager will looks like when the task runs for around 5 times- enter image description here where many instances of Windows Power Shell & Console Windows host are running,, so can anyone adivce on this please ? i though the related processes will end as soon as the windows task ends..


Solution

  • -NoExit means no exit... So if you want it to close after the script is executed, then don't use it.