Skip to content

Instantly share code, notes, and snippets.

@reosablo
Created August 25, 2021 16:06
Show Gist options
  • Select an option

  • Save reosablo/cdaaa7ab3f519ac8abb3fb77a8875d10 to your computer and use it in GitHub Desktop.

Select an option

Save reosablo/cdaaa7ab3f519ac8abb3fb77a8875d10 to your computer and use it in GitHub Desktop.
Enable / Disable VirtualMachinePlatform
@powershell/c '#'+(gc \"%~f0\"-ra)^|iex&exit/b
$ErrorActionPreference = 'Stop'
try {
$FeatureName = 'VirtualMachinePlatform'
$Feature = Get-WindowsOptionalFeature -Online -FeatureName $FeatureName
$Enabled = $Feature.State -eq 'Enabled'
$Feature
$Question = "$(@('Enable', 'Disable')[+$Enabled]) ${FeatureName}?"
$UserAccepted = $Host.UI.PromptForChoice($PSCommandPath, $Question, @('&Yes', '&No'), 0) -eq 0
if (-not $UserAccepted) {
return
}
if ($Enabled) {
Disable-WindowsOptionalFeature -Online -FeatureName $FeatureName
} else {
Enable-WindowsOptionalFeature -Online -FeatureName $FeatureName
}
} catch {
"$_"
pause
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment