Skip to content

Instantly share code, notes, and snippets.

@flandersen
Last active February 9, 2024 09:04
Show Gist options
  • Save flandersen/204bfed9642640fedebb7cbf2a07c695 to your computer and use it in GitHub Desktop.
Save flandersen/204bfed9642640fedebb7cbf2a07c695 to your computer and use it in GitHub Desktop.
Windows Task Scheduler job failed to access local git repository

Problem description

I was trying to run TrackGpo from the Windows Task Scheduler by executing the following:

Program/Script: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Parameter: -ExecutionPolicy Bypass -Command "Invoke-GpoTracking -GpoRepo C:\GPO_Repo -WorkingDir C:\GPO_WorkingDir"

Running the task resulted in the following error:
Task Scheduler successfully completed task "\Backup GPOs" , instance "{300bfea1-ba81-4a4a-9350-205a9fd27d76}" , action "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" with return code 2147942401.

Debugging

I have created a batch file with the following content, which I then ran with the job:

git -C C:\GPO_Repo status 1>C:\temp\output.log 2>&1

The result looks like this:

fatal: detected dubious ownership in repository at 'C:/GPO_Repo'
'C:/GPO_Repo' is owned by:
	'S-1-5-21-3636845873-337328340-1997893300-1106'
but the current user is:
	'S-1-5-18'
To add an exception for this directory, call:
	git config --global --add safe.directory C:/GPO_Repo

My user was the owner of "C:\GPO_Repo".

Solution

Making the SYSTEM user the owner of the folder solved the problem. Adding the directory to the safe.directory is also an option, but then has to be done using the SYSTEM user as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment