Issue with powershell script to run with task scheduler

MoTaar 310 Reputation points
2024-12-05T17:22:07.6266667+00:00

Hi everyone,

I’m running into an issue with Task Scheduler on Windows, and I hope someone can help me troubleshoot.

I have a task configured to run a PowerShell script to fetch Azure Sign-In Logs. However, it keeps failing with the following error:

arduino
Copy code
Task

I’ve verified the following:

  1. The PowerShell script runs fine when executed manually.
  2. The task is set to run whether the user is logged in or not.

I’ve done some research and found that error code 2147942667 might be related to a file or path issue, but I’m not entirely sure how to resolve it.

Has anyone encountered this issue before? Could it be related to how the arguments or the path to powershell.exe are configured in Task Scheduler? Any guidance would be appreciated!

Thank you in advance!

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2024-12-05T18:11:03.24+00:00

    Add a Start-Transcript statement as the first executable line in your script and a Stop-Transcript as the last executable line.

    Use -Path to specify a file name to some folder on your C: drive.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1

    Make sure that your .PS1 script file is on the C: drive. The task scheduler does a user impersonation and not a full desktop logon so mapped drives may not be available.

    Review the transcript log file for errors.

    0 comments No comments

  2. Rich Matheisen 47,901 Reputation points
    2024-12-05T20:43:15.42+00:00

    That error (2147942667 = 0x8007010b = ERROR_DIRECTORY) may be related to the "Start in" value of the task (or the Program/script value).

    The tasks "Program/Script" property will accept quotation marks around the value (if, for example, there as spaces in the directory name).

    The tasks "Start in" property doesn't require them and doesn't allow them.

    You may also have, for example, a trailing space in a path name.

    If you can't spot the error, reenter the values and try running the task again.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.