VMware: Disable HotPlug capability for virtual machines with PowerCLI
Last week I had to change VMX files for 500 XenDesktop machines because the users where able to eject removable devices
To mass disable HotPlug capability by editing the .vmx
file via PowerCLI I used the following script:
$key = "devices.hotplug" $value = "false" get-cluster "CL02.XD" | get-VM -Name 000-CXD* | foreach { $vm = Get-View $_.Id $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec $vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue $vmConfigSpec.extraconfig[0].Key=$key $vmConfigSpec.extraconfig[0].Value=$value $vm.ReconfigVM($vmConfigSpec) }
Optional (manual) options:
You can disable HotPlug capability using the vSphere Client or by editing the .vmx
file.
Note: You can disable HotPlug capability for PCI devices such as e1000 or vmxnet3 NICs.
To disable HotPlug capability using the vSphere Client:
- Connect to the ESXi/ESX host or vCenter Server using the vSphere Client.
- Power off the virtual machine.
- Right-click the virtual machine and click Edit Settings.
- Click the Options tab.
- Click General > Configuration Parameters > Add Row.
- Insert a new row with the name
devices.hotplug
and a value offalse
. - Power on the virtual machine.
To disable HotPlug capability using the vSphere Web Client:
- From a web browser, connect to the vSphere Web Client.
- Log in with Administrator credentials.
- Navigate to the virtual machine you want to modify.
- Right-click the virtual machine and select Edit Settings.
- Click the VM Options tab.
- Click Advanced > Edit Configuration > Add Row.
- Insert a new row with the name
devices.hotplug
and a value offalse
. - Power on the virtual machine.
To disable HotPlug capability by editing the .vmx
file:
- Power off the virtual machine.
- Access the ESXi/ESX service console using an SSH client.
- Open the virtual machine configuration file (
.vmx
) in a text editor. The default location is:
/vmfs/volumes/datastore_name/vm_name/vm_name.vmx
- Add the line:
devices.hotplug = "false"
Note: This setting does not interfere with HotPlug CPU/memory. - Save and close the file.
- Power on the virtual machine.
- More information:
Hey Sander,
Great post, but note that this line;
$vm.ReconfigVM($vmConfigSpec)
Doesn’t work with PowerCLI 6+.
I had to use;
$vm.ExtensionData.ReconfigVM($vmConfigSpec)
Thanks!
Christian.
Thank you very much Chris!
Nuestros créditos rápidos no te decepcionarán.