locked
Powershell script (v5) running from scheduled task on W12 R2 server fails randomly in the middle of execution. OpCode (2), Task Category "Task completed". RRS feed

  • Question

  • I have a powershell script (v5) running in a scheduled task on a Windows 2012 R2 server, that creates a list of new user accounts in Active Directory.  It runs daily, and 98% it finishes successfully.  The other 2% of the time, it fails with an Opcode (2) partially through completion. If I re-run the task in Task Scheduler, it runs to completion just fine. Nothing in the event log or the PS script log that gives me any clue as to why the just seems to abend for no reason. Any ideas?
    Thursday, February 8, 2018 4:52 PM

All replies

  • 1. You never supplied your script.

    2. This may be an issue with task scheduler, so not a PowerShell question.

    3. Add logging and error handling to your script to generate the real error, as the code you are getting is from Task Scheduler.


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Thursday, February 8, 2018 5:12 PM
  • 1.  The script is over 3000+ lines of code, so I didn't think it wise to attach the script.  The basic function of the script is creating/modifying user objects within our Active Directory domain from a CSV file of employee data.  It also interfaces with Exchange to create mailboxes for new A.D. user objects.

    2.  I've already posted this question on the W12 forum, and they suggested this forum.

    3.  I have plenty of logging and error handling in the script, but since it seems to be dying at random points within the code, and re-running the script doesn't replicate the issue, it's very difficult to know where the error is coming from.

    Just not sure where to go from here.

    Thursday, February 8, 2018 5:30 PM
  • You dont have anything in your error logs indicating when it failed, at what line, and maybe the cause?

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Thursday, February 8, 2018 5:54 PM
  • No sir.  The last line of the log just displays the last log entry I added before running the next set of commands.  it's almost like the powershell.exe process was killed, or the task scheduled was stopped.  If that was the case however, I would assume I would see something in the event log pointing to the process being stopped.  I have a recovery process in place that if this happens, the script will restart and pick up where it left off.  This happened twice last month, 1 time the month before, but never in the same spot, and when the recovery job kicks off the process again, it always finishes the script without error.

    At this point, I guess I'll have to add more error-checking somehow to figure this out.  I'm almost positive this is erroring due to some external issue (i.e. domain not responding, or network issues), since the syntax of the script itself is fine, and runs 99% of the time without issue.  I just can't prove it.

    Thursday, February 8, 2018 6:03 PM
  • Hi,

    According to your situation, I would suggest you open up a case with Microsoft Technical Support to see if they could get more information regarding this problem:
    https://www.microsoft.com/en-us/worldwide.aspx

    Thanks for your understanding and cooperation.

    Best Regards,
    Albert

    Please remember to mark the replies as an answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, February 9, 2018 8:31 AM