Robocopy and Powershell


DennisG

Active member
Member
Local time
12:30 PM
Posts
36
OS
Windows 11 Professional 24H2
For some years now I have used Robocopy to back up my data and personal files (which I keep on a separate partition from Windows). I run this with a simple batch file which I created. Recently, I have been thinking that I should be able to do this with a Powershell script. Now, I am a "silver surfer", not a programmer, and my attempts were not successful.
I have not yet joined the AI revolution but I thought this might be the time so I asked ChatGPT to write me a script. It asked for my batch file and in a split second it came back with a Powershell script. I tried it and it worked ! I'm actually very impressed.
Both Robocopy and Powershell come with Windows, so no need to use anything else imho. At lease not for what I need. This is the script it produced for anyone who wishes to try it - modified to your own situation of course:

# PowerShell Backup Script using Robocopy
Clear-Host

Write-Host "****************************"
Write-Host "*** ROBOCOPY BACKUP SCRIPT ***"
Write-Host "****************************`n"
Write-Host "This program backs up files from local PC to external drive"
Write-Host "==================================================================="
Write-Host "*** 1_Open Drive D:"
Write-Host "*** 2_Connect External Drive"
Write-Host "*** 3_Run Veracrypt"
Write-Host "*** 4_Mount Veracrypt Volumes - T:\ and W:\"
Write-Host "==================================================================="
Pause

# Set date format (dd-MM-yyyy)
$MyDate = Get-Date -Format "dd-MM-yyyy"

# Define a helper function to run Robocopy with consistent options
function Run-Robocopy {
param (
[string]$Source,
[string]$Destination,
[string]$LogPrefix
)

$logFile = "D:\Backup_Logs\${LogPrefix}_$MyDate.txt"
robocopy $Source $Destination /e /np /tee /mt:8 /R:10 /W:2 /log:"$logFile"
Pause
}

# Start Robocopy jobs
Run-Robocopy -Source "T:\" -Destination "W:\" -LogPrefix "My-Files"
Run-Robocopy -Source "C:\Users\Dennis\Downloads" -Destination "E:\Downloads" -LogPrefix "Downloads"
Run-Robocopy -Source "C:\Users\Dennis\Desktop\Misc" -Destination "E:\Misc" -LogPrefix "Misc"
Run-Robocopy -Source "C:\Users\Dennis\Desktop\Batch_Files" -Destination "E:\Batch_Files" -LogPrefix "Batch_Files"
Run-Robocopy -Source "D:\Bridge Notes" -Destination "E:\Bridge Notes" -LogPrefix "Bridge_Notes"
Run-Robocopy -Source "D:\Outlook Backup" -Destination "E:\Outlook Backup" -LogPrefix "Outlook-D"

Write-Host "===================================="
Write-Host "*** THE PROGRAM HAS BEEN COMPLETED ***"
Write-Host "===================================="
 

My Computer

System One

  • OS
    Windows 11 Professional 24H2
    Computer type
    Laptop
    Manufacturer/Model
    Thinkpad T480
    CPU
    Intel i5 8th Gen
Back
Top Bottom