Check for automatic checkpoint support before configuring

The AutomaticCheckpointsEnabled option may not always be available
depending on the version in use. Check for support before applying
the configured value. If automatic checkpoints are to be enabled
and support is not available, force an error.
This commit is contained in:
Chris Roberts 2018-09-05 13:37:45 -07:00
parent 7a7ae59704
commit 1f74aedeaa
1 changed files with 5 additions and 0 deletions

View File

@ -106,6 +106,11 @@ if($EnableAutomaticCheckpoints) {
}
try {
if($autochecks -eq 1 -and (Get-Command Hyper-V\Set-VM).Parameters["AutomaticCheckpointsEnabled"] -eq $null) {
Write-ErrorMessage "AutomaticCheckpointsEnabled is not available"
exit 1
}
Hyper-V\Set-VM -VM $VM -AutomaticCheckpointsEnabled $autochecks
} catch {
Write-ErrorMessage "Failed to ${AutoAction} automatic checkpoints on VM: ${PSItem}"