Created
August 25, 2021 16:06
-
-
Save reosablo/cdaaa7ab3f519ac8abb3fb77a8875d10 to your computer and use it in GitHub Desktop.
Enable / Disable VirtualMachinePlatform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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