Skip to content

Instantly share code, notes, and snippets.

Forked from j1n6/noop_sync.vbs
Created August 29, 2022 09:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save perXautomatik/ae488d4f97292be35befb207fd08fff8 to your computer and use it in GitHub Desktop.
Powershell to sync and push to remote git repository via Windows Scheduled Tasks
' Hack to workaround the Powershell Console popup running on a Windows Scheduled Task
' Powershell limitations:
' Add this file in the same git root directory as the sync.ps1
Dim shell,command
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim sScriptDir : sScriptDir = oFSO.GetParentFolderName(WScript.ScriptFullName)
command = "powershell.exe -nologo -File " & sScriptDir & "\sync.ps1"
Set shell = CreateObject("WScript.Shell")
shell.Run command,0
function GitCommitAndPush {
$dateString = Get-Date -UFormat "%Y-%m-%d %H:%M:%S"
git add .
git commit -q -m "$($dateString)"
git push -q
function GitPull {
git pull
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Set-Location -Path $scriptPath
if(git status --porcelain |Where {$_ -match '^\?\?'}){
# untracked files exist
Exit 0
elseif(git status --porcelain |Where {$_ -notmatch '^\?\?'}) {
# uncommitted changes
Exit 0
else {
# tree is clean
Exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment