Windows task schduler keep showing 0x41301

I believe this shows the problem:

  <Actions Context="Author">
    <Exec>
      <Command>C:\Users\user.service\Documents\AppPoolActivation.ps1</Command>
    </Exec>
  </Actions>

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:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

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.