5
1
I have wrote the following .ps1 file:-
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$request = [System.Net.WebRequest]::Create("https://localhost/")
$response = $request.GetResponse()
$response.Close()
and I set a task within the windows server 2012 r2 task scheduler , to call te above ps1 file.now I run this task manually, but it keep showing "0x41301" which means it is still running ... although if I directly run the above code inside PowerShell window it will end in less than a second ? so why calling this ps1 using task Schuler will never ends ?
--Edit-- here is the XML exported:-
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2016-02-09T00:35:11.5514762</Date>
<Author>ad-services\user.service</Author>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<Repetition>
<Interval>PT5M</Interval>
<Duration>PT30M</Duration>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
<StartBoundary>2016-02-09T19:30:01</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-20</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Users\user.service\Documents\AppPoolActivation.ps1</Command>
</Exec>
</Actions>
</Task>
1You can enable that the task always ends in x minutes, hours, days, etc. Is it really a problem to kill the task this way? I've seen it before that a script ends, but the process remains active for some reason. – LPChip – 2016-02-08T17:42:59.460
1Can you post the exported XML from your Task so we can see exactly how you're setting it up? – Ƭᴇcʜιᴇ007 – 2016-02-08T17:51:26.473
@LPChip I did not get your point what is wrong with my script ? – John John – 2016-02-09T00:31:04.947
@Ƭᴇcʜιᴇ007 I edit my question with the generated XML.. can you please check ? thanks – John John – 2016-02-09T00:43:21.937
@JohnJohn My point is, that your script can be fine and run until completion, but the process still remains active and that keeps the scheduled task from stopping normally. – LPChip – 2016-02-09T09:40:49.310