VMware Cloud Community
dwchan
Enthusiast
Enthusiast
Jump to solution

Devices.Hotplug syntax error

I am change my VM devices to disable hotplug.  The code I am using are

if ($strUseCase -eq 'Horizon'){
My-Logger "Disable the Ability to Add and Remove Virtual Hardware While the VM Is Running"
$oVMName = VMware.VimAutomation.Core\Get-VM -Name $strVMName
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.OptionValue
$extra.Key = 'Devices.Hotplug'
$extra.Value = $false
$spec.ExtraConfig += $extra
$oVMName.ExtensionData.ReconfigVM($spec)
}

I am getting the following error

[11-23-2020_03:47:29] Disable the Ability to Add and Remove Virtual Hardware While the VM Is Running
Exception calling "ReconfigVM" with "1" argument(s): "A specified parameter was not correct:
config.extraConfig["Devices.Hotplug"]"
At line:10 char:5
+ $oVMName.ExtensionData.ReconfigVM($spec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

I double-check the spelling and can't seem to find the error.  What am I missing?

0 Kudos
1 Solution

Accepted Solutions
dwchan
Enthusiast
Enthusiast
Jump to solution

FYI, got it to work, all I did was changing the syntax from

$extra.Value = $false

to 

$extra.Value = false

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

It looks like that VM is powered on.
You can't change that setting while the VM is powered on.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
dwchan
Enthusiast
Enthusiast
Jump to solution

Hum, let me double-check, pretty sure it was off.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

It could also be the casing you used.

Afaik, that parameter is all lower-case, like devices.hotplug 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
dwchan
Enthusiast
Enthusiast
Jump to solution

Just double check, VM is power off and switch key to all lowercase, still the same error.  Any suggestion?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you follow the procedure outlined in KB1012225?
Especially the steps for the parent VM.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
dwchan
Enthusiast
Enthusiast
Jump to solution

FYI, got it to work, all I did was changing the syntax from

$extra.Value = $false

to 

$extra.Value = false