none
Scheduled Task repeated trigger failure with a managed service account RRS feed

  • Question

  • I have set up a scheduled task on Windows Server 2012 R2 Standard, and it's failing ONLY when I set the trigger to repeat or stop task.  It doesn't matter if it is a one time, daily, weekly, or monthly trigger.  It can be multiple triggers or a single trigger.  It will fail when run on schedule or on demand with a specified file not found 0x80070002 error.  And the event log entry is kind enough to not tell me which specified file it is unable to find.

    The task runs fine under my own domain account with local administrative rights.  And without either of these settings configured, the task will run fine under the managed service account credentials - on schedule or on demand, with a single trigger or multiple triggers.

    The task runs a powershell script, using a single action which includes the full path to powershell.exe, the arguments include the full path to the script file, and all paths inside the script are fulling qualified.

    It is currently set to run using a group managed service account (gMSA).  The account has local administrative privileges, has rights to log on as a batch job, has full rights to all file locations, and without the repeat or stop task settings configured, runs successfully.

    I have tried creating the task manually in the GUI, creating it through the schtasks command-line utility, and the scheduled tasks powershell cmdlets.  All exhibit the same behavior.

    Wednesday, March 30, 2016 7:07 PM

Answers

  • I never did find anything better for Server 2012 Rw.  But, FYI, I just tested on Server 2016, and the problem seems to have been fixed.  I'm using the long-term service build 14393 from 10/2016, DataCenter edition.

    I know it's not much of an answer, but I think I'm satisfied as I'm moving away from 2012 in my environments.


    -EJJ


    • Edited by EJsquared Friday, August 3, 2018 10:44 PM
    • Marked as answer by EJsquared Friday, August 3, 2018 10:44 PM
    Friday, August 3, 2018 10:43 PM

All replies

  • Hi EJsquared,

    Thanks for posting here.

    >>I have set up a scheduled task on Windows Server 2012 R2 Standard, and it's failing ONLY when I set the trigger to repeat or stop task.

    You could set the triggers as figure below:

    Or, you could selected the "stop the task if it runs than:" option in settings lab.

    >>It will fail when run on schedule or on demand with a specified file not found 0x80070002 error.  And the event log entry is kind enough to not tell me which specified file it is unable to find.

    When specifying a program or a script in Task Scheduler, you need to make sure the file is in the path.

    Otherwise you need to specify the full path.

    Please help me to check your script's path, try to use the relative path rather than absolute path.

    Best regards,


    Andy_Pan

    Thursday, March 31, 2016 6:40 AM
    Moderator
  • Here is what is currently configured for the action:
    Action: Start a program
    Program/script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
        -I selected Browse and navigated to the PoSh exe and it filled in the full path automatically
    Add Arguments (optional): -noprofile -windowstyle hidden -file D:\Scripts\Ad\dc_daily_check_trusts.ps1
    Start in (optional): d:\scripts\ad

    The script location is not in the path, so I need to include the full path.  I tested:
    -removing the 'Start In' value so only the full path was referenced in the arguments - failed
    -removing the full path from arguments, and keeping the path in 'Start in' - failed
    -removing the full path to the script file completely - failed

    I currently have 1 trigger defined, Daily at 12am.  It runs fine like this.  As soon as I configure the 'Repeat task every' setting or the 'Stop task if it runs longer than' setting, the 'Last Run Result' immediately changes to 'The system cannot find the file specified', and it hasn't even run yet.

    If I remove the repeat or stop settings, it runs fine.

    I will use multiple triggers if I have to, but I shouldn't have to configured 24 triggers for this to run hourly every day.  It runs successfully when using a regular user account with the repeat value enabled.  It fails when using a group managed service account with the repeat value enabled.

    Thursday, March 31, 2016 2:17 PM
  • Although I have not found an answer, I did find a work around - I created a separate task to write a custom event log entry every hour, then set the task running powershell script to trigger off of the custom event.

    1. Create custom app source for the System log where 'MyApp' is whatever you want to call it - [System.Diagnostics.EventLog]::CreateEventSource('MyApp', 'System')

    2. Created a powershell script with the following, and I specify the event ID as one of the arguments, in this case 0, but I can now use it for other tasks if needed by adjusting the event ID:
    Write-EventLog -LogName System -Source MyApp -EventId $eID -EntryType Information -Message "Custom event log entry for the Active Directory health check scripts"

    3. Create a task to run the powershell script to write the custom event log, I run it under the local system account, with a daily trigger that repeats every hour.

    4. Finally, I set my original task using the gMSA and I want to run hourly I'm having trouble with to trigger on an event:


    -EJJ

    • Proposed as answer by David Zemdegs Friday, August 3, 2018 4:16 AM
    Tuesday, April 5, 2016 12:53 PM
  • Hi Ejj,

    Although I have not found an answer, I did find a work around - I created a separate task to write a custom event log entry every hour, then set the task running powershell script to trigger off of the custom event.

    1. Create custom app source for the System log where 'MyApp' is whatever you want to call it - [System.Diagnostics.EventLog]::CreateEventSource('MyApp', 'System')

    2. Created a powershell script with the following, and I specify the event ID as one of the arguments, in this case 0, but I can now use it for other tasks if needed by adjusting the event ID:
    Write-EventLog -LogName System -Source MyApp -EventId $eID -EntryType Information -Message "Custom event log entry for the Active Directory health check scripts"

    3. Create a task to run the powershell script to write the custom event log, I run it under the local system account, with a daily trigger that repeats every hour.

    4. Finally, I set my original task using the gMSA and I want to run hourly I'm having trouble with to trigger on an event:


    Thanks for your sharing and feedback.

    We will keep tracing of this issue, if we have any solutions for this issue, will updating soon.

    Thanks again for your understanding.

    Best regards,


    Andy_Pan

    Wednesday, April 6, 2016 7:14 AM
    Moderator
  • Just wanted to provide a follow-up.  It took some time, and jumping through a bunch of hoops for internal security policies, but I was finally able to roll this out in our production forest.

    This forest started out as Server 2003, and has since been upgraded.  It is currently at Server 2008 R2 all domain and forest levels.  All DCs are running server 2012 R2.

    I am seeing the exact same behavior in the production forest as I do in our dev forest, with no trust between the forests.  The task runs fine as a scheduled task running daily under gMSA credentials.  As soon as I set the trigger to repeat, or set the trigger properties to stop the task after a custom time, the task fails with an error that the system cannot find the file specified.

    I have to delete the trigger and create a new trigger before the task will run correctly again.

    Same issue, multiple forests.


    -EJJ

    Thursday, July 7, 2016 8:50 PM
  • I have also had this issue.  Particularly with Managed Service Accounts, and with triggers that are set to repeat.

    The only repetition I have been able to get working is one in a "One-Time" trigger, which I then set to repeat indefinitely. This is fine if you want to run every hour (or every twenty minutes, in my case) until the end of time, but not if you want to do anything fancy.

    All other trigger types fail with the 0x80070002 error, if repetition is configured.  I cannot use a Daily trigger to run at 00:00, 02:00 and 04:00 on any given day, for instance, by setting a start time of 00:00 and setting repetition to Every 2 hours for up to 5 hours.  Instead, I need three Daily triggers (without repetition), at 00:00, 02:00 and 04:00.

    I have been using schtasks.exe with XML to configure the tasks with MSAs, as I understood the GUI not to support these accounts. 

    My working repetition trigger XML is:

        <TimeTrigger>
          <Repetition>
            <Interval>PT20M</Interval>
            <StopAtDurationEnd>false</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2000-01-01T00:00:00</StartBoundary>
          <Enabled>true</Enabled>
        </TimeTrigger>

    My non-working trigger XML is:

        <CalendarTrigger>
          <Repetition>
            <Interval>PT2H</Interval>
            <Duration>PT5H</Duration>
            <StopAtDurationEnd>false</StopAtDurationEnd>
          </Repetition>
          <StartBoundary>2000-01-01T00:00:00</StartBoundary>
          <Enabled>true</Enabled>
          <ScheduleByDay>
            <DaysInterval>1</DaysInterval>
          </ScheduleByDay>
        </CalendarTrigger>

    Thursday, June 1, 2017 7:43 PM
  • Im having the same issue. It must be a limitation but I love your workaround!
    Friday, August 3, 2018 4:17 AM
  • I never did find anything better for Server 2012 Rw.  But, FYI, I just tested on Server 2016, and the problem seems to have been fixed.  I'm using the long-term service build 14393 from 10/2016, DataCenter edition.

    I know it's not much of an answer, but I think I'm satisfied as I'm moving away from 2012 in my environments.


    -EJJ


    • Edited by EJsquared Friday, August 3, 2018 10:44 PM
    • Marked as answer by EJsquared Friday, August 3, 2018 10:44 PM
    Friday, August 3, 2018 10:43 PM
  • This was exactly my issue, lifesaver! Thanks!

    Thursday, November 1, 2018 2:47 PM
  • As another follow-up, the reason for the issue can be found in this other thread down near the bottom, with a registry edit solution:

    https://social.technet.microsoft.com/Forums/en-US/6585da08-ab84-4917-8e6b-ee6506f0a45f/gmsa-task-scheduler-with-repetition-fails-appears-to-be-a-bug?forum=winserver8gen


    -EJJ

    Tuesday, December 11, 2018 9:51 PM