Skip to content

Instantly share code, notes, and snippets.

@perXautomatik
Forked from j1n6/noop_sync.vbs
Created August 29, 2022 09:37
Embed
What would you like to do?
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: https://github.com/PowerShell/PowerShell/issues/3028
'
' 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
GitPull
if(git status --porcelain |Where {$_ -match '^\?\?'}){
# untracked files exist
GitCommitAndPush
Exit 0
}
elseif(git status --porcelain |Where {$_ -notmatch '^\?\?'}) {
# uncommitted changes
GitCommitAndPush
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