Created
September 19, 2016 17:34
-
-
Save andrii-riabchun/ea28a6d7db7de068c6b60caf8a99ee37 to your computer and use it in GitHub Desktop.
Powershell Script for easy toggling Microsoft Hyper-V Windows Feature
This file contains 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
#Requires -RunAsAdministrator | |
# Script for enabling/disabling Hyper-V. | |
Param( | |
[string]$action | |
) | |
function usage { | |
Write-Host "usage: | |
$($args[0]) status - hyper-v status | |
$($args[0]) enable - enables hyper-v with all tools | |
$($args[0]) disable - disables hyper-v with all tools" | |
} | |
function getFeatures { | |
return Get-WindowsOptionalFeature -Online ` | |
| Where-Object {$_.FeatureName.StartsWith("Microsoft-Hyper-V")} | |
} | |
switch ($action) { | |
"status" { getFeatures | Format-List } | |
"enable" { | |
Enable-WindowsOptionalFeature -Online -FeatureName $( | |
getFeatures | ForEach-Object {"$($_.FeatureName)"} | |
) | |
} | |
"disable" { | |
Disable-WindowsOptionalFeature -Online -FeatureName $( | |
getFeatures | ForEach-Object {"$($_.FeatureName)"} | |
) | |
} | |
Default {usage} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment