none
Scheduled task on VM does not run RRS feed

  • Question

  • I am trying to get a scheduled task to run on a Windows Server 2012 R2 virtual machine. When I RDP in and test the task, everything works manually. The task is scheduled to run nightly and it appears to run successfully (the scheduled task history says that it successfully runs, the exit code of the action is 0). However, the text logs that my process should generate are not created.

    The task runs a batch file that acts as a wrapper around a powershell script. The powershell script queries a database, creates an export file, and generates logs. This is the batch file:

    Call PowerShell -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dp0\my_script.ps1""' -Verb RunAs}"

    Powershell Version: 5.1.14409.1018

    Scheduled Task Configuration

    • Run whether user is logged in or not: TRUE
    • Run with highest privileges: TRUE
    • User who runs the task: Administrator
    • Start in: (hard-coded full path to the batch file location)
    • Start task only if computer is on AC Power: FALSE

    The task runs successfully under the following conditions:

    Note: success = logs generated by powershell script

    • Logged in as admin, double-click the batch file.
    • Right-click the task in task scheduler and run it.
    • Set the task scheduler to run in five minutes, and keep my RDP session active.
    • Set the task scheduler to run in five minutes, and close my RDP session.

    The task finishes and has an exit code of 0, but powershell script does not run under following conditions:

    • Set the task scheduler to run nightly, and close my RDP session

    So the exit code tells me that the batch file is successfully run, but why doesn't the powershell script run?

    I am stumped. What is preventing this from running the nightly job?

    Wednesday, April 8, 2020 7:01 PM