← script library

Automated File Backup Script

Backup & RecoveryJanuary 10, 2025

In this post, we present a PowerShell script designed for automated file backup. This script helps users to safely back up important files and folders to a designated location, ensuring data security and easy retrieval.

powershell
$sourcePath = 'C:\ImportantFiles'
$backupPath = 'D:\Backup'

if (-Not (Test-Path -Path $backupPath)) {
    New-Item -ItemType Directory -Path $backupPath
    Write-Host "Backup directory created: $backupPath"
}

Get-ChildItem -Path $sourcePath -File | ForEach-Object {
    Copy-Item -Path $_.FullName -Destination $backupPath -Force
    Write-Host "Copied: $($_.Name) to $backupPath"
}

Write-Host "Backup completed successfully! All files from '$sourcePath' have been copied to '$backupPath'."

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.