Skip to content

Instantly share code, notes, and snippets.

@cernoel
Created August 6, 2020 08:21
Show Gist options
  • Save cernoel/b742689652eb6dda04535a4e6d40a6e4 to your computer and use it in GitHub Desktop.
Save cernoel/b742689652eb6dda04535a4e6d40a6e4 to your computer and use it in GitHub Desktop.
backup vmx and vmxf files from vsphere cluster with powercli
# 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