VMware: Disable HotPlug capability for virtual machines with PowerCLI

3

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:

  1. Connect to the ESXi/ESX host or vCenter Server using the vSphere Client.
  2. Power off the virtual machine.
  3. Right-click the virtual machine and click Edit Settings.
  4. Click the Options tab.
  5. Click General > Configuration Parameters > Add Row.
  6. Insert a new row with the name devices.hotplug and a value of false.
  7. Power on the virtual machine.

To disable HotPlug capability using the vSphere Web Client:

  1. From a web browser, connect to the vSphere Web Client.
  2. Log in with Administrator credentials.
  3. Navigate to the virtual machine you want to modify.
  4. Right-click the virtual machine and select Edit Settings.
  5. Click the VM Options tab.
  6. Click Advanced > Edit Configuration > Add Row.
  7. Insert a new row with the name devices.hotplug and a value of false.
  8. Power on the virtual machine.

To disable HotPlug capability by editing the .vmx file:

  1. Power off the virtual machine.
  2. Access the ESXi/ESX service console using an SSH client.
  3. Open the virtual machine configuration file (.vmx) in a text editor. The default location is:
    /vmfs/volumes/datastore_name/vm_name/vm_name.vmx
  4. Add the line:
    devices.hotplug = "false"
    Note: This setting does not interfere with HotPlug CPU/memory.
  5. Save and close the file.
  6. Power on the virtual machine.
    More information:

VMware

About Author

3 thoughts on “VMware: Disable HotPlug capability for virtual machines with PowerCLI

Leave a Reply

Your email address will not be published. Required fields are marked *