Created
May 17, 2023 16:56
-
-
Save sh1dow3r/a32ff8ce2e7b0d0c9ec225ec954da51c to your computer and use it in GitHub Desktop.
PowerCLI vCenter VMs backup to local machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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