I have written a solution to this in TypeScript using the Aria Build Tools
https://github.com/vmware/build-tools-for-vmware-aria
The first step is to take the new size and update the VcVirtualDisk CapacityInKB value
public VcVirtualMachineIncreaseVcVirtualDiskSize(@notNull @notEmpty @required objVcVirtualMachine: VcVirtualMachine, @notNull @notEmpty @required objVcVirtualDisk: VcVirtualDisk, @notNull @notEmpty @required intDiskSizeGB: number): boolean {
let intKilobytes: number = 1024 * 1024;
let intNewSizeKilobytes: number = objVcVirtualDisk.capacityInKB + intDiskSizeGB * intKilobytes;
objVcVirtualDisk.capacityInKB = intNewSizeKilobytes;
let objVcVirtualDeviceConfigSpec: VcVirtualDeviceConfigSpec = this.VcVirtualDeviceConfigSpecCreate(objVcVirtualDisk, VcVirtualDeviceConfigSpecOperation.edit);
let blnResult: boolean = this.VcVirtualMachineReconfigureDevice(objVcVirtualMachine, objVcVirtualDeviceConfigSpec);
return blnResult;
}
The second step is to create a new VcVirtualDeviceConfigSpec
private VcVirtualDeviceConfigSpecCreate(@notNull @notEmpty @required objVcVirtualDevice: VcVirtualDevice, @notNull @notEmpty @required enumVcVirtualDeviceConfigSpecOperation: VcVirtualDeviceConfigSpecOperation, @notNull @notEmpty @required enumVcVirtualDeviceConfigSpecFileOperation: VcVirtualDeviceConfigSpecFileOperation = null, @notNull @notEmpty @required arrVcVirtualMachineProfileSpec: VcVirtualMachineProfileSpec[] = []): VcVirtualDeviceConfigSpec {
let objVcVirtualDeviceConfigSpec: VcVirtualDeviceConfigSpec = new VcVirtualDeviceConfigSpec();
objVcVirtualDeviceConfigSpec.operation = enumVcVirtualDeviceConfigSpecOperation;
objVcVirtualDeviceConfigSpec.fileOperation = enumVcVirtualDeviceConfigSpecFileOperation
objVcVirtualDeviceConfigSpec.device = objVcVirtualDevice;
objVcVirtualDeviceConfigSpec.profile = arrVcVirtualMachineProfileSpec;
return objVcVirtualDeviceConfigSpec;
}
The third step is to create an array of VcVirtualDeviceConfigSpec with this single item
private VcVirtualMachineReconfigureDevice(@notNull @notEmpty @required objVcVirtualMachine: VcVirtualMachine, @notNull @notEmpty @required objVcVirtualDeviceConfigSpec: VcVirtualDeviceConfigSpec): boolean {
let arrVcVirtualDeviceConfigSpec: VcVirtualDeviceConfigSpec[] = [];
arrVcVirtualDeviceConfigSpec.push(objVcVirtualDeviceConfigSpec);
let blnResult: boolean = this.VcVirtualMachineReconfigureDevices(objVcVirtualMachine, arrVcVirtualDeviceConfigSpec);
return blnResult;
}
The fourth step is to create a VcVirtualMachineConfigSpec
private VcVirtualMachineReconfigureDevices(@notNull @notEmpty @required objVcVirtualMachine: VcVirtualMachine, @notNull @notEmpty @required arrVcVirtualDeviceConfigSpec: VcVirtualDeviceConfigSpec[]): boolean {
let objVcVirtualMachineConfigSpec: VcVirtualMachineConfigSpec = new VcVirtualMachineConfigSpec();
objVcVirtualMachineConfigSpec.deviceChange = arrVcVirtualDeviceConfigSpec;
let blnResult: boolean = this.VcVirtualMachineReconfigure(objVcVirtualMachine, objVcVirtualMachineConfigSpec);
return blnResult;
}
The fifth step is to Reconfigure the VcVirtualMachine using the VcVirtualMachineConfigSpec
private VcVirtualMachineReconfigure(@notNull @notEmpty @required objVcVirtualMachine: VcVirtualMachine, @notNull @notEmpty @required objVcVirtualMachineConfigSpec: VcVirtualMachineConfigSpec): boolean {
try {
Locking.lock(`${objVcVirtualMachine.name}-Modification`);
let objVcTask: VcTask = objVcVirtualMachine.reconfigVM_Task(objVcVirtualMachineConfigSpec);
this.WaitForVcTaskEnd(objVcTask, 1);
Locking.unlock(`${objVcVirtualMachine.name}-Modification`);
return true;
}
catch (objException) {
Locking.unlock(`${objVcVirtualMachine.name}-Modification`);
let objError: Error = objException as Error;
this.objLogger.error(`Name: ${objError.name}`);
this.objLogger.error(`Message: ${objError.message}`);
if (objException instanceof VcConcurrentAccess) {
this.objLogger.error(`Thrown if the changeVersion does not match the server's changeVersion for the configuration.`);
}
else if (objException instanceof VcCpuHotPlugNotSupported) {
this.objLogger.error(`Thrown if the current configuration of the VM does not support hot - plugging of CPUs.`);
}
else if (objException instanceof VcDuplicateName) {
this.objLogger.error(`Thrown if the specified name already exists in the parent folder.`);
}
else if (objException instanceof VcFileFault) {
this.objLogger.error(`Thrown if there is a problem creating or accessing the virtual machine's files for this operation. Typically a more specific fault like NoDiskSpace or FileAlreadyExists is thrown.`);
}
else if (objException instanceof VcInsufficientResourcesFault) {
this.objLogger.error(`Thrown if this operation would violate a resource usage policy.`);
}
else if (objException instanceof VcInvalidDatastore) {
this.objLogger.error(`Thrown if the operation cannot be performed on the target datastores.`);
}
else if (objException instanceof VcInvalidName) {
this.objLogger.error(`Thrown if the specified name is invalid.`);
}
else if (objException instanceof VcInvalidPowerState) {
this.objLogger.error(`Thrown if the power state is poweredOn and the virtual hardware cannot support the configuration changes.`);
}
else if (objException instanceof VcInvalidState) {
this.objLogger.error(`Thrown if the operation cannot be performed in the current state of the virtual machine.For example, because the virtual machine's configuration is not available.`);
}
else if (objException instanceof VcMemoryHotPlugNotSupported) {
this.objLogger.error(`Thrown if the current configuration of the VM does not support hot - plugging of memory.`);
}
else if (objException instanceof VcRuntimeFault) {
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.`);
}
else if (objException instanceof VcTaskInProgress) {
this.objLogger.error(`Thrown if the virtual machine is busy.`);
}
else if (objException instanceof VcTooManyDevices) {
this.objLogger.error(`Thrown if the device specifications exceed the allowed limits.`);
}
else if (objException instanceof VcVmConfigFault) {
this.objLogger.error(`Thrown if the spec is invalid.Typically, a more specific subclass is thrown.`);
}
else if (objException instanceof VcVmWwnConflict) {
this.objLogger.error(`Thrown if the WWN of the virtual machine has been used by other virtual machines.`);
}
return false;
}
}
The sixth step is to wait for the VcTask to complete and handle any error that occur.
public WaitForVcTaskEnd(@notNull @notEmpty @required objVcTask: VcTask, @notNull @notEmpty @required intPollRate: number): any {
while (objVcTask.info !== null) {
let objVcTaskInfoState: VcTaskInfoState = objVcTask.info.state;
if (objVcTaskInfoState.value === "success") {
break;
}
else if (objVcTaskInfoState.value === "error") {
if (objVcTask.info.error.localizedMessage === null) {
throw `Task '${objVcTask.info.name}' has encountered an unknown error`;
}
else {
throw `Task '${objVcTask.info.name}' error: '${objVcTask.info.error.localizedMessage}'`;
}
}
else if (objVcTaskInfoState.value === "running") {
if (objVcTask.info.progress === null) {
this.objLogger.info(`${objVcTask.info.name} - Queued or In Progress...`);
}
else {
this.objLogger.info(`${objVcTask.info.name} - Progress: ${objVcTask.info.progress} %`);
}
}
System.sleep(intPollRate * 1000);
}
this.objLogger.info(objVcTask.info.name + " - Completed");
System.sleep(2 * 1000);
if (objVcTask !== null && objVcTask.info !== null && objVcTask.info.result_AnyValue !== null) {
let objVcSdkConnection: VcSdkConnection = objVcTask.sdkConnection;
return VcPlugin.convertToVimManagedObject(objVcSdkConnection, objVcTask.info.result_AnyValue);
}
else {
return null;
}
}
------------------------------
Simon Sparks
Automation & Orchestration Consultant
North West England, UK, Europe
Broadcom Employee
------------------------------
Original Message:
Sent: Jun 11, 2025 03:09 PM
From: pizzle85
Subject: Resizing VM disk through VCO
This will resize SCSI Controller 0 Hard Disk 1 to the value of new_disk_size_gb
devices = vm.config.hardware.device;for each (device in devices) { if (device instanceof VcVirtualDisk) { if (device.controllerKey == 1000 && device.unitNumber == 0) { device.capacityInKB = new_disk_size_gb * 1024 * 1024 config_spec = new VcVirtualMachineConfigSpec() device_config_specs = new Array() device_config_spec = new VcVirtualDeviceConfigSpec() device_config_spec.device = device device_config_spec.operation = VcVirtualDeviceConfigSpecOperation.edit device_config_specs.push(device_config_spec) config_spec.deviceChange = device_config_specs vm.reconfigVM_Task(config_spec) } }}
Original Message:
Sent: Aug 08, 2011 11:46 AM
From: deqcan
Subject: Resizing VM disk through VCO
Hi to all,
I'm trying to resize a VM disk through the VCO, without success.
Actually I wrote the following script:
//*************************************************
//vm is a VC:VirtualMachine parameter
//newSize is a number parameter
//return type is VC:Task
if (!vm) return null;
var devices = vm.config.hardware.device;
var firstDisk = null;
var diskSize = -1;
var newSizeInKB = newSize * 1024 * 1024;
//Finds the first VM disk
for (var i in devices) {
if (devices[i] instanceof VcVirtualDisk) {
firstDisk = devices[i];
}
}
diskSize = firstDisk.capacityInKB;
if (diskSize < 0 || newSizeInKB <= diskSize) return null; //No disk found, or the newSize is too small
var _key = firstDisk.key;
var _controllerKey = firstDisk.controllerKey;
var _unitNumber = firstDisk.unitNumber;
var _backing = firstDisk.backing;
var _newDiskSizeInKB = newSizeInKB;
System.log("key:" + _key + "\nControllerKey:" + _controllerKey + "\nUnitNumber:" + _unitNumber + "\nBacking:" + _backing);
var _newVirtualDevice = new VcVirtualDisk();
_newVirtualDevice.controllerKey = _controllerKey;
_newVirtualDevice.key = _key;
_newVirtualDevice.backing = _backing;
_newVirtualDevice.unitNumber = _unitNumber;
_newVirtualDevice.capacityInKB = _newDiskSizeInKB;
System.log("key:" + _newVirtualDevice.key + "\nControllerKey:" + _newVirtualDevice.controllerKey + "\nUnitNumber:" + _newVirtualDevice.unitNumber + "\nBacking:" + _newVirtualDevice.backing + "\nNew Size:" + _newVirtualDevice.capacityInKB);
var _virtualDeviceConfigSpec = new VcVirtualDeviceConfigSpec();
_virtualDeviceConfigSpec.device = _newVirtualDevice;
_virtualDeviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;
_virtualDeviceConfigSpec.fileOperation = VcVirtualDeviceConfigSpecFileOperation.replace;
var _virtualMachineConfigSpec = new VcVirtualMachineConfigSpec();
_virtualMachineConfigSpec.deviceChange = new Array();
_virtualMachineConfigSpec.deviceChange.push(_virtualDeviceConfigSpec);
return vm.reconfigVM_Task(_virtualMachineConfigSpec);
//*************************************************
Executing the code I can see the task starting and immediately ending in vCenter without errors, but the vm disk size remains the same.
Could you help me?