Skip to content

Commit

Permalink
choco: handle error during enabling of hyper-v
Browse files Browse the repository at this point in the history
catch error that might be thrown by cmdlet enabling hyper-v and fail
the installation if error occurs
  • Loading branch information
anjannath authored and praveenkumar committed Apr 26, 2023
1 parent 0135fca commit e63f223
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packaging/chocolatey/crc/tools/crcprerequisitesetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,29 @@ function Install-Hyperv {
if ($enabled) {
Write-Host "Hyper-V is already enabled"
} else {
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart | Out-Null
Write-Host -ForegroundColor Red "Hyper-V has been enabled, please reboot to complete installation"
try {
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart | Out-Null
Write-Host -ForegroundColor Red "Hyper-V has been enabled, please reboot to complete installation"
}
catch {
Write-Host -ForegroundColor Red "Failed to enable Hyper-V, aborting installation"
Set-PowershellExitCode 1
}
}
}
"Server" {
$enabled = (Get-WindowsFeature -Name "Hyper-V" | Select-Object -ExpandProperty InstallState).ToString().Equals("Installed")
if ($enabled) {
Write-Host "Hyper-V is already enabled"
} else {
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Confirm:$false -Restart:$false | Out-Null
Write-Host -ForegroundColor Red "Hyper-V has been enabled, please reboot to complete installation"
try {
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -Confirm:$false -Restart:$false | Out-Null
Write-Host -ForegroundColor Red "Hyper-V has been enabled, please reboot to complete installation"
}
catch {
Write-Host -ForegroundColor Red "Failed to enable Hyper-V, aborting installation"
Set-PowershellExitCode 1
}
}
}
}
Expand Down

0 comments on commit e63f223

Please sign in to comment.