I have wrote the following .ps1 file:-

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

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">
    <Principal id="Author">
  <Actions Context="Author">
  • 1
    You 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 Feb 8 '16 at 17:42
  • 1
    Can you post the exported XML from your Task so we can see exactly how you're setting it up? – Ƭᴇcʜιᴇ007 Feb 8 '16 at 17:51
  • @LPChip I did not get your point what is wrong with my script ? – John John Feb 9 '16 at 0:31
  • @Ƭᴇcʜιᴇ007 I edit my question with the generated XML.. can you please check ? thanks – John John Feb 9 '16 at 0:43
  • @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 Feb 9 '16 at 9:40

I believe this shows the problem:

  <Actions Context="Author">

You shouldn't just put a .PS1 script in as the command you want to run, it will cause it to fail, or do weird things. :)

Instead in the Task, change the "Program/script" you want to run to:


Add the script via the "Arguments" field of the task, as well as include Execution Policy changes (if required). i.e:

-ExecutionPolicy Bypass -file "C:\Users\user.service\Documents\AppPoolActivation.ps1"

You may also want to change the "Start in" field to match the path that the script exists in, i.e.: C:\Users\user.service\Documents\.

Piece of advice, don't store the script in a user's profile folder, as it can cause access issues. Instead make a folder (outside of the Users folder) to hold your script(s), and ensure the user account used to run the task has appropriate access.

  • I follow your steps and now I last run is showing 0x1 ? – John John Feb 9 '16 at 15:00
  • @JohnJohn 0x1 means succesful if I'm not mistaken. – LPChip Feb 11 '16 at 8:28
  • @Techie007 now the only approach which works in my case, is that I create a .bat file which calls the .pst file,, then inside the task scheduler i specify the path to the .bat file inside the "Program/script" ... – John John Feb 12 '16 at 16:13
  • 2
    @LPChip 0x0 is SUCCESS. Any non-zero return value usually means error. – Dan Dec 8 '16 at 20:29

I had this problem as I had the task set to "run whether user is logged on or not".. When I switched it to "Run only when user is logged on" and tested it, I realized that I had a PAUSE in one of my batch files that I forgot to remove!

I know this is likely not related but hopefully it helps someone out in the future!

  • 1
    VLQ Reviewers: This is a legitimate attempt to answer the question. A pause command would indeed produce the task status code reported by the OP. – I say Reinstate Monica Nov 28 '17 at 18:18
  • It solve my problem too – sam Oct 31 '18 at 6:30

Or simply in "Action" tab fill Program/script: powershell Addarguments (optional): -NonInteractive -file "C:\yourscript.ps1"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.