Adding Hyper-V-less boot entry with PowerShell

Developers often encounter the need to run virtual machines using VirtualBox and Hyper-V-based mobile emulators on the same machine (for example Windows Mobile or Visual Studio Android Emulator). Unfortunately only one of the two can be enabled at once. The easiest solution is to create two boot entries and disable Hyper-V in one of them.

CMD way

The awesome Scott Hanselman provided a quick command line solution in one of his blogposts.

As part of creating a Chocolatey based PowerShell install script for my most used tools after computer reinstall, I wanted to make this automatic and preferably skip the copy-paste step.

PowerShell script

The script is very simple:

$bcdResult = ( bcdedit /copy `{current`} /d "No Hyper-V" ) | Out-String
$bcdResult -match "\{.+\}"
bcdedit /set $matches[0] hypervisorlaunchtype off

First line of the script runs the bcdedit  tool and create a copy of the current boot entry. The result is a string in the following form:

The entry was successfully copied to {XX-XX-XXX-XXXX-XXXXXXXX}.

We need to parse out the identifier enclosed between curly brackets. This is just the job for regular expressions on the second line of the script. The matches are stored in the  $matches  variable.

Finally we can use the identifier to modify the boot entry to disable Hyper-V on the third line.

And that’s it! Pretty simple but convenient. You can simply run the script and the new Hyper-V-less boot entry will be created for you automatically. Be sure to run the script with administrator permissions.

You can download the script here.

Buy me a coffeeBuy me a coffee

1 thought on “Adding Hyper-V-less boot entry with PowerShell”

  1. Hi ! When i run a debug with an application on my VS exspress for Windows phone my computer tell me that there isn’t Hyper-V on my system. Does exists a mode to bypass this problem ? (For example a script with powershell….)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


This site uses Akismet to reduce spam. Learn how your comment data is processed.