# XenServer VM-Export # Author: Mauricio Schäpers # Description: Exports all vms into a given directory $xeserver = "192.168.0.1s" $xeuser = "root" $xepw = "s3cr3tP@55w0rd" $xvadir = "D:\ExportFolder" #Check where xencenter is installed $xecmd = "c:\program files (x86)\citrix\xencenter\xe.exe" if (!(Test-Path $xecmd)) { $xecmd = "c:\program files\citrix\xencenter\xe.exe"} #Get the UUIDs of all powered-off machines $colvmuuids = (& $xecmd -s $xeserver -u $xeuser -pw $xepw vm-list is-control-domain=false power-state=halted params=uuid --minimal) -split "," foreach ($vmuuid in $colvmuuids){ #Get the name label for filenameing $vmnamelabel = & $xecmd -s $xeserver -u $xeuser -pw $xepw vm-list uuid=$vmuuid params=name-label --minimal Write-Host ############## Write-Host Starting $vmnamelabel & $xecmd -s $xeserver -u $xeuser -pw $xepw vm-export uuid=$vmuuid compress=true filename=$xvadir"\"$vmnamelabel".xva" Write-Host Finished! } #Get the UUIDs of all user generated templates $coltemplateuuids = & $xecmd -s $xeserver -u $xeuser -pw $xepw template-list live=true foreach ($templateuuid in $coltemplateuuids){ #Get the name label for filenameing $templatelabel = & $xecmd -s $xeserver -u $xeuser -pw $xepw vm-list uuid=$vmuuid params=name-label --minimal Write-Host ############## Write-Host Starting $templatelabel & $xecmd -s $xeserver -u $xeuser -pw $xepw vm-export uuid=$vmuuid compress=true filename=$xvadir"\Template_"$vmnamelabel".xva" Write-Host Finished! } Write-Host -ForegroundColor Yellow "All Jobs completed!"