HyperVDsc icon indicating copy to clipboard operation
HyperVDsc copied to clipboard

VMHyperV: Support AutomaticStartAction and AutomaticStopAction

Open janegilring opened this issue 2 years ago • 3 comments

Resource proposal

I suggest adding support for configuring AutomaticStartAction and AutomaticStopAction, which can be configured using Set-VM:

Set-VM -Name $VmName -AutomaticStartAction Start/StartIfRunning/Nothing -AutomaticStopAction Save/TurnOff/ShutDown

Proposed properties

Property Data type Description Default value Allowed values
AutomaticStartAction String Configures automatic start action for VM None Start/StartIfRunning/Nothing
AutomaticStopAction String Configures automatic stop action for VM None Save/TurnOff/ShutDown

Special considerations or limitations

Modifying these properties can only be done when the VM is powered off

janegilring avatar Dec 30 '23 09:12 janegilring

So if these properties can only be modified when the VM is off, should they only be allowed to be configured when the VM is created, or should these also be enforced if they diverge? If the later how should there be an opt-in for turning off and on a VM to be able to enforce these values?

johlju avatar Dec 31 '23 09:12 johlju

Good question.

I was just looking at how this works for the ProcessorCount property, and noticed it will turn off the VM when the value changes if RestartIfNeeded is set to true. Otherwise, it fails with the following error:

PowerShell DSC resource DSC_VMHyperV  failed to execute Set-TargetResource functionality with error message: System.InvalidOperationException: Can not change
properties for VM 'Disk1_vm' in 'Running' state unless 'RestartIfNeeded' is set to true.

I think AutomaticStartAction/AutomaticStopAction should follow the same pattern.

janegilring avatar Jan 01 '24 20:01 janegilring

Great, that will do.

johlju avatar Jan 02 '24 10:01 johlju