From cb2dc3cbf8b84ad50acb3e4cfd42791331f00722 Mon Sep 17 00:00:00 2001 From: Tom Peltonen Date: Mon, 16 Aug 2021 11:21:11 +1000 Subject: [PATCH] Adding sample folder --- samples/Robocopy_sample.ps1 | 30 ++++++++++++++++++++++++++++++ samples/Samples.md | 6 ++++++ 2 files changed, 36 insertions(+) create mode 100644 samples/Robocopy_sample.ps1 create mode 100644 samples/Samples.md diff --git a/samples/Robocopy_sample.ps1 b/samples/Robocopy_sample.ps1 new file mode 100644 index 0000000..961d685 --- /dev/null +++ b/samples/Robocopy_sample.ps1 @@ -0,0 +1,30 @@ +param ( + [Parameter(Mandatory)] + [String] $Source, + [Parameter(Mandatory)] + [String] $Destination +) + + +$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 + robocopy `"C:\Users\tom\Small Share\misc_05`" `"$Destination`" /e /copy:DAT /dcopy:DAT /log+:./robocopy.log + 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 +} diff --git a/samples/Samples.md b/samples/Samples.md new file mode 100644 index 0000000..4057d6d --- /dev/null +++ b/samples/Samples.md @@ -0,0 +1,6 @@ +# Samples + +This folder contains sample scripts using ``PeterDocs`` + +The samples are intended to be self documenting. Please adjust +the code to suit your circumstances.