Pre- and Post-Run Actions

Pre- and post-run actions let you attach automated steps to any SyncFolder task — before the sync begins and after it finishes. Use them to prepare the environment, chain tasks together in a sequence, or shut down the computer automatically once a long sync is complete.

Overview

Each task in SyncFolder can optionally carry two action hooks. They are configured in the Advanced Task Settings popup and run automatically every time the task executes — whether triggered manually, by a schedule, or by another task.

HookWhen it runsAvailable action types
Pre-runImmediately before the sync startsPowerShell script
Post-runImmediately after the sync finishes (successfully)PowerShell script  Â·  Execute another task  Â·  Shut down / hibernate

Post-run actions only fire when the task completes without errors. If the sync is aborted or encounters a critical error, post-run actions are skipped.

Pre-Run Action – PowerShell Script

The pre-run hook executes a single PowerShell command or script before any files are touched. This is the right place for tasks that need to set up the environment — mapping a network drive, stopping a service, or creating a lock file.

Configuring the Script

  • Open the task and click Advanced task settings to open the settings dialog.
  • Under Before execution, switch on Execute Powershell command before sync.
  • Type your PowerShell command or script path in the text box that appears.
  • Click Test to run the command immediately and inspect the result.
  • The output panel appears below the text box. Close it with the × button when done.

The Test button runs your script in exactly the same context as a real task run — same working directory, same user account, same PowerShell execution policy. What you see in the output panel is exactly what SyncFolder will see.

Script Examples

Map a network drive
New-PSDrive -Name "Z" `
  -PSProvider FileSystem `
  -Root "\\server\share" `
  -Persist
Stop a service before sync
Stop-Service -Name "MyAppService" `
             -Force
# Wait until stopped
Start-Sleep -Seconds 2

If the pre-run script exits with a non-zero exit code, SyncFolder treats it as a failure and cancels the sync. Make sure your script ends cleanly — or explicitly exit with exit 0 when errors are non-fatal.

Post-Run Actions

Post-run actions are configured in the Advanced Task Settings popup and execute after a successful sync. There are two primary post-run action types — a PowerShell script and Execute another task — and one additional option: Shut down / hibernate. The shutdown/hibernate option always runs last, after any PowerShell script and after the chained task has been triggered. Each type is enabled independently.

PowerShell Script

Identical in setup to the pre-run script. Use this to undo any environment changes made by the pre-run action — removing a drive mapping, restarting a service, or writing a completion log entry.

Remove the mapped drive
Remove-PSDrive -Name "Z" -Force
Restart service after sync
Start-Service -Name "MyAppService"
# Log completion
Add-Content "C:\Logs\sync.log" `
            "Sync completed $(Get-Date)"

Execute Another Task Optional

This action launches a second SyncFolder task automatically after the current one succeeds. Select the target task from the dropdown list, which shows all tasks currently defined in your SyncFolder configuration.

  • Under After execution, switch on Execute another task when this one completes successfully.
  • Select the desired task in the Task to be executed dropdown.
  • The selected task will run only if the triggering task completed successfully.
  • The chained task runs with its own settings, including any of its own pre- and post-run actions.

This feature makes it possible to implement parent–child–grandchild (rotation) logic: Task A triggers Task B on success, and Task B triggers Task C on success. Each task in the chain runs independently — with its own exclusion filters, sync mode, and action hooks.

Task Chain Example

Task A – Nightly BackupSyncs D:\Work → NAS.

Post-run: Execute Task B
Task B – Offsite CopySyncs NAS → Cloud storage.

Post-run: Execute Task C
Task C – Archive RotationRemoves copies older than 30 days.

Post-run: (none)

Avoid creating circular chains (Task A → Task B → Task A). SyncFolder does not currently detect cycles, so a circular chain will keep running until you manually stop it or the system is restarted.

Shut Down or Hibernate Optional

When a long-running sync is finished, SyncFolder can automatically shut down or hibernate the computer. This is useful for overnight backups where you want the machine to power off without manual intervention.

  • Under After execution, find Shut down computer after task execution and choose Yes, shut down or Yes, hibernate (the default is No, do not shut down).
  • Set the delay (After … seconds, up to 300 seconds). The default is 60 seconds.
  • When the task finishes, SyncFolder shows the notification SyncFolder is about to sign you out: "Unless you click "Cancel" or tap this notification, your computer will automatically shut down in … seconds."
  • If you do nothing, the action executes when the delay has passed.
  • Click Cancel (or tap the notification) to cancel the shutdown or hibernation.
SettingValue / RangeDescription
ActionNo, do not shut down · Yes, shut down · Yes, hibernateWhich power action to perform
DelayUp to 300 seconds (default 60)Time between notification and action
User overrideAlways availableCancel in the notification cancels the action

Set the delay to at least 30 seconds so you have enough time to react to the notification, especially if SyncFolder is running in the background or on a secondary monitor.

When you start such a task yourself (or from the command line), SyncFolder first asks: "The task you want to execute is configured to shut down the computer when the task has finished. Do you want to power off the computer after execution?" — click Yes to shut down afterwards or No to keep the computer running this time.

The shut-down/hibernate action is executed after the post-run PowerShell script and after the chained task has been started (not completed). If you chain to another task, the computer may shut down before that task finishes.

Execution Order

When all post-run actions are enabled simultaneously, they execute in the following order:

  1. Pre-run PowerShell script runs.
  2. Task sync executes.
  3. Post-run PowerShell script runs (on success).
  4. Chained task is triggered (on success).
  5. Shutdown / hibernate countdown notification appears.

If the post-run PowerShell script fails (non-zero exit code), the chained task and the shutdown/hibernate action are both skipped. Ensure your cleanup scripts exit cleanly.

Tips and Best Practices

Always test scripts firstUse the Test button before saving. A script that works interactively in PowerShell may behave differently when run by SyncFolder (no profile, restricted execution policy, different working directory).
Keep scripts idempotentWrite scripts so they can safely run twice without side effects — in case a task is retried. For example, check whether a drive is already mapped before trying to map it.
Use exit codes deliberatelyReturn exit 0 for success and exit 1 (or any non-zero code) to signal a real failure. Only fail the pre-run when you genuinely want to block the sync.
Plan chain order carefullyWhen designing a multi-task chain, consider what happens if one task fails mid-chain. Each task's post-run action only fires on success, so a failure stops the chain at that point.