A PowerShell script to automate and manage Robocopy tasks using a centralized JSON configuration file. It supports parallel execution, configurable logging, and email notifications, making it ideal for scheduled data synchronization and backup jobs.
- Concurrent Execution: Run multiple Robocopy tasks simultaneously to optimize large-scale file operations.
- Centralized Configuration: All tasks and settings are defined in a single, easy-to-read JSON file.
- Flexible Task Definition: Configure tasks using standard Robocopy arguments or by referencing a pre-existing Robocopy job file (.RCJ).
- Remote Operation: Execute Robocopy commands on local or remote machines using PowerShell remoting.
- Comprehensive Logging: Save detailed Robocopy and script error logs to files or the Windows Event Log.
- Email Notifications: Send a summary of all executed tasks, errors, and actions via email, with options for when to send.
- Environment Variable Support: Use environment variables for sensitive information like passwords or server names, enhancing security and portability.
- PowerShell 7.x or later: This script is built for modern PowerShell.
- Robocopy.exe: The executable
robocopy.exe
, available on all Windows operating systems. - Emailing Prerequisites (Optional): If you plan to use email notifications, install the
MailKit
andMimeKit
NuGet packages.Install-Package -Name 'MailKit' -Source 'https://www.nuget.org/api/v2' -Scope 'AllUsers' -SkipDependencies Install-Package -Name 'MimeKit' -Source 'https://www.nuget.org/api/v2' -Scope 'AllUsers' -SkipDependencies
- Clone this repository to your local machine:
git clone https://github.com/DarkLite1/robocopy.git cd robocopy
- Review
Example.json
to understand the configuration options. - Create your own configuration file (e.g.,
MyConfig.json
) based onExample.json
.
Execute the script from PowerShell, providing the path to your configuration JSON file.
& '.\Robocopy.ps1' -ConfigurationJsonFile '.\MyConfig.json'
For automated, recurring executions (e.g., via Windows Task Scheduler), you'll typically invoke the script using pwsh.exe -Command
. This allows you to pass parameters directly.
- Program:
pwsh.exe
- Arguments:
-Command "& 'C:\Robocopy\Robocopy.ps1' -ConfigurationJsonFile 'C:\MyConfig.json'; exit $LASTEXITCODE"