Last active
February 27, 2019 11:17
-
-
Save m4ss1m0g/b461c8317e9132056edec28439a4a701 to your computer and use it in GitHub Desktop.
HyperV and VmWare switching
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
function Switch-Virtualization | |
{ | |
# Advanced parameters | |
# https://ss64.com/ps/syntax-function-advanced.html | |
[CmdletBinding()] # Add cmdlet features. | |
Param( | |
[Parameter(Mandatory=$true)] | |
[ValidateSet("vmware", "hyperv")]$Virtualization, | |
[Parameter(Mandatory=$false)] | |
[switch]$Reboot | |
) | |
Process | |
{ | |
Try | |
{ | |
Write-Verbose -Message "Entering the try block" | |
if ($Virtualization -eq "vmware") | |
{ | |
Write-Verbose -Message "Selected vmware" | |
bcdedit /set hypervisorlaunchtype off | |
} | |
if ($Virtualization -eq "hyperv") | |
{ | |
Write-Verbose -Message "Selected hyperv" | |
bcdedit /set hypervisorlaunchtype auto | |
} | |
if ($Reboot) | |
{ | |
Write-Verbose -Message "Selected the reboot" | |
Restart-Computer -Confirm | |
} | |
else | |
{ | |
Write-Info "Reboot to take effect" | |
} | |
} | |
Catch | |
{ | |
Write-Verbose -Message "Entering the BEGIN block [$($MyInvocation.MyCommand.CommandType): $($MyInvocation.MyCommand.Name)]." | |
Log-Error -LogPath $sLogFile -ErrorDesc $_.Exception -ExitGracefully $True | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment