Skip to content

Instantly share code, notes, and snippets.

@sh1dow3r
Created May 17, 2023 16:56
Show Gist options
  • Save sh1dow3r/a32ff8ce2e7b0d0c9ec225ec954da51c to your computer and use it in GitHub Desktop.
Save sh1dow3r/a32ff8ce2e7b0d0c9ec225ec954da51c to your computer and use it in GitHub Desktop.
PowerCLI vCenter VMs backup to local machine
# Set vCenter server details
$vcServer="vcenter.local"
$vcUsername="[email protected]"
$vcUsername="VeryStrongPassword@123"
# Connect to vCenter
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -confirm:$false
Connect-VIServer -Server $vcServer -User $vcUsername -Password $vcPassword
# List of VMs to backup
$vmList = @("NextCloud","Ubuntu", "Win10")
# Local backup path
$backupPath = "C:\Backup"
# Loop through each VM and export the VApp
foreach ($vmName in $vmNames) {
try {
Get-VM -Name $vmName | Export-VApp -Destination $backupPath
Write-Host "Backup of VM '$vmName' completed successfully."
}
catch {
Write-Host "Error occurred during backup of VM '$vmName': $_"
}
}
# Disconnect from vCenter
Disconnect-VIServer -Server $vcServer -Confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment