PeterDocs/samples/Robocopy_sample.ps1

35 lines
1.3 KiB
PowerShell
Raw Normal View History

2021-08-16 01:21:11 +00:00
param (
[Parameter(Mandatory)]
[String] $Source,
[Parameter(Mandatory)]
[String] $Destination
)
2021-08-18 13:36:07 +00:00
# Note that there is a path limitation for files of 260 characters
# beyond which PeterDocs will fail
# You could also use drive mapping to overcome this
# New-PSDrive "X" -PSProvider FileSysytem -Root "$Source"
2021-08-16 01:21:11 +00:00
$step ="Starting"
Try {
$step ="Creating initial reconcile"
New-PeterReconcile -ReconcileFile .\myrobocopy.csv -SourceFolder $Source
$step ="Running robocopy"
Write-Host "Running robocopy for source '$Source' and destination '$Destination'"
# Change the command line switches to suit
2021-08-18 13:36:07 +00:00
robocopy `"$Source`" "$Destination" /e /copy:DAT /dcopy:DAT /log+:./robocopy.log /r:1000 /w:10
2021-08-16 01:21:11 +00:00
if ($LastExitCode -lt 8) {
Write-Host "Robocopy succeeded"
} else {
Write-Host "Robocopy failed with exit code:" $LastExitCode
throw "Robocopy error"
}
$step ="Running copy reconcile"
Compare-Peter -ReconcileFile .\myrobocopy.csv -RestoreFolder $Destination
# You can modify the code here to add a success email notification
} Catch {
Write-Host "Error: $_"
Write-Error "Processing encountered error at step '$step'"
# You can modify the catch to add a simlpe email notification on errors
}