Created
August 6, 2020 08:21
-
-
Save cernoel/b742689652eb6dda04535a4e6d40a6e4 to your computer and use it in GitHub Desktop.
backup vmx and vmxf files from vsphere cluster with powercli
This file contains 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
# https://communities.vmware.com/thread/278559 | |
$Destination = "/mnt/backup0/vmx/" | |
Connect-VIServer -Server <server> -User <user> -Password <password> | |
Get-VM | ` | |
Get-View | ` | |
ForEach-Object { | |
$vmxfile = $_.Config.Files.VmPathName | |
$dsname = $vmxfile.split(" ")[0] | |
$ds_name = $dsname.Substring(1,$dsname.Length-2) | |
$ds = Get-Datastore -Name $ds_name | |
New-PSDrive -Name ds -PSProvider VimDatastore -Root '/' -Location $ds | |
Write-Host "ds:\$($vmxfile.split(']')[1].TrimStart(' '))" | |
Copy-DatastoreItem -Item "ds:\$($vmxfile.split(']')[1].TrimStart(' '))" -Destination $Destination | |
Copy-DatastoreItem -Item "ds:\$($vmxfile.split(']')[1].TrimStart(' '))f" -Destination $Destination | |
Remove-PSDrive -Name ds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment