← script library

Automated Hyper-V VM Backup Script

Hyper-VJanuary 10, 2025

This PowerShell script automates the process of backing up your Hyper-V virtual machines. It simplifies the backup routine, ensuring your data is safe and easy to restore.

powershell
$backupDirectory = "C:\HyperVBackups"

if (-Not (Test-Path -Path $backupDirectory)) {
    New-Item -ItemType Directory -Path $backupDirectory
}

$vms = Get-VM
foreach ($vm in $vms) {
    $sourcePath = $vm.Path
    $destinationPath = Join-Path -Path $backupDirectory -ChildPath "$($vm.Name).vhdx"
    Copy-Item -Path "$sourcePath\*.vhdx" -Destination $destinationPath -Recurse
}

Write-Host "Backup of Hyper-V VMs completed successfully to $backupDirectory"

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.