# Define source and destination paths
$sourcePaths = @("C:\ImportantFiles", "D:\CriticalFolder")
$backupDir = "C:\Backups\FileBackup"
$zipFile = "$backupDir\Backup_$(Get-Date -Format 'yyyyMMdd_HHmm').zip"
# Create backup directory if it doesn't exist
if (!(Test-Path -Path $backupDir)) { New-Item -ItemType Directory -Path $backupDir }
# Copy files and folders to backup directory
foreach ($path in $sourcePaths) {
Copy-Item -Path $path -Destination $backupDir -Recurse
}
# Compress files into a ZIP archive
Compress-Archive -Path "$backupDir\*" -DestinationPath $zipFile -Force
Write-Output "Files and folders backed up and compressed to $zipFile"
• Explanation: This script copies files and folders to a backup directory and then compresses them into a ZIP file.