Backing up Workstation VMs with PowerShell
It’s pretty common for me to backup my Workstation VMs and I’m always looking for quick way to accomplish this. I’ve been using SyncBack Free for many years but most recently I’ve out grown it a bit. In this blog I’ll show you the script I wrote to backup my VM’s to a target location.
My Workstation server has many hard disks with many folders for my VM’s. I backup my VM’s to a large HD and then regularly I’ll off load these backups to a NAS for archive purposes. This keeps the VM’s local for quick restores and the NAS provides some further protection.

My PowerShell script is rather simple. Define my sources, choose a target folder, and then use Robocopy to copy the files. Next I update my backup notes in a text file and I’m done.
It’s a pretty simple process but it works quite well.
#Define Sources
$source1 = “d:\Virtual Machines\VCF 9 vSAN ESA 3 Node”
$source2 = “f:\Virtual Machines\VCF 9 vSAN ESA 3 Node”
$source3 = “g:\Virtual Machines\VCF 9 vSAN ESA 3 Node”
$source4 = “h:\Virtual Machines\VCF 9 vSAN ESA 3 Node”
$source5 = “i:\Virtual Machines\VCF 9 vSAN ESA 3 Node”
$source6 = “j:\Virtual Machines\VCF 9 vSAN ESA 3 Node”
$source7 = “k:\Virtual Machines\VCF 9 vSAN ESA 3 Node”
#Function user selected destination folder
function Select-FolderDialog {
param([string]$Description=”Select a folder”,
[string]$RootFolder=”MyComputer”)
# Load the necessary assemblyAdd-Type -AssemblyName System.Windows.Forms# Create an instance of the FolderBrowserDialog object$objForm = New-Object System.Windows.Forms.FolderBrowserDialog$objForm.RootFolder = $RootFolder$objForm.Description = $Description# Show the dialog box$Show = $objForm.ShowDialog()# Check if the user clicked 'OK' and return the selected pathif ($Show -eq "OK") { return $objForm.SelectedPath} else { Write-Error "Operation cancelled by user."}# Clean up the object$objForm.Dispose()
}
#Prompt User for destination folder
$selectedFolderPath = Select-FolderDialog -Description “Please choose the destination folder”
if ($selectedFolderPath) {
Write-Host “You selected: $selectedFolderPath”
# You can now use $selectedFolderPath in the rest of your script
}
#Start Robocopy
robocopy $source1 $selectedFolderPath /e
robocopy $source2 $selectedFolderPath /e
robocopy $source3 $selectedFolderPath /e
robocopy $source4 $selectedFolderPath /e
robocopy $source5 $selectedFolderPath /e
robocopy $source6 $selectedFolderPath /e
robocopy $source7 $selectedFolderPath /e
#Pause Exit
Write-Output “Script finished. Press Enter to exit.”
pause