Skip to content

Instantly share code, notes, and snippets.

@m4ss1m0g
Last active February 27, 2019 11:17
Show Gist options
  • Save m4ss1m0g/b461c8317e9132056edec28439a4a701 to your computer and use it in GitHub Desktop.
Save m4ss1m0g/b461c8317e9132056edec28439a4a701 to your computer and use it in GitHub Desktop.
HyperV and VmWare switching
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