0

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..

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
John John
  • 1
  • 72
  • 238
  • 501
  • 4
    If you don't want the process to keep running, why specify `-NoExit`? – Mathias R. Jessen Feb 14 '16 at 02:00
  • you can use taskkill to end the processes – user642958 Feb 14 '16 at 02:02
  • @MathiasR.Jessen seems i misunderstood the -NoExit, i although it will prevent ending the process during the powershell script execution,,, but seems it means to never end the process even after it is completed... – John John Feb 15 '16 at 15:44
  • @johnG , `-NoExit` is used if you want to continue after running the script. Ex. if you call the script simply to setup the console, load some modules etc. – Frode F. Feb 15 '16 at 17:12

1 Answers1

3

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

Frode F.
  • 52,376
  • 9
  • 98
  • 114