Orchestrator Function: vCenter Virtual Machine Migrate

by Simon Sparks · 5 January 2026

To use this function add it to the class library file named vCenterServerService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: vCenterServerService.ts

privateVcVirtualMachineMigrate(objVcVirtualMachine:VcVirtualMachine,objVcResourcePool:VcResourcePool,objVcHostSystem:VcHostSystem,strVcVirtualMachineMovePriority:"highPriority"|"defaultPriority"|"lowPriority",strVcVirtualMachinePowerState:"poweredOn"|"poweredOff"|"suspended"):void{

try{
letobjVcTask:VcTask=objVcVirtualMachine.migrateVM_Task(objVcResourcePool,objVcHostSystem,VcVirtualMachineMovePriority[strVcVirtualMachineMovePriority],VcVirtualMachinePowerState[strVcVirtualMachinePowerState])

this.WaitForVcTaskEnd(objVcTask,2);
}catch (objException){
Utilities.logException(objException,this.objLogger,"VcVirtualMachineMigrate");

if (objExceptioninstanceofVcFileFault){
this.objLogger.error(`Thrown if if there is a problem accessing the virtual machine's files for this operation. Typically a more specific fault FileLocked is thrown.`);
}
elseif (objExceptioninstanceofVcInsufficientResourcesFault){
this.objLogger.error(`Thrown if this operation would violate a resource usage policy.`);
}
elseif (objExceptioninstanceofVcInvalidPowerState){
this.objLogger.error(`Thrown if the state argument is set and the virtual machine does not have that power state.`);
}
elseif (objExceptioninstanceofVcInvalidState){
this.objLogger.error(`Thrown if the operation cannot be performed because of the virtual machine's current state. For example, if the virtual machine configuration information is not available.`);
}
elseif (objExceptioninstanceofVcMigrationFault){
this.objLogger.error(`Thrown if it is not possible to migrate the virtual machine to the destination host. This is typically due to hosts being incompatible, such as mismatch in network polices or access to networks and datastores. Typically, a more specific subclass is thrown.`);
}
elseif (objExceptioninstanceofVcNoActiveHostInCluster){
this.objLogger.error(`Thrown if a target host is not specified and the cluster associated with the target pool does not contain at least one potential target host. A host must be connected and not in maintenance mode in order to be considered as a potential target host.`);
}
elseif (objExceptioninstanceofVcRuntimeFault){
this.objLogger.error(`Thrown if any type of runtime fault is thrown that is not covered by the other faults; for example, a communication error.`);
}
elseif (objExceptioninstanceofVcTimedout){
this.objLogger.error(`Thrown if one of the phases of the migration process times out.`);
}
elseif (objExceptioninstanceofVcVmConfigFault){
this.objLogger.error(`Thrown if a virtual machine configuration issue prevents the estimation.Typically, a more specific fault is thrown.`);
}
}
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like