Checking Hypervisor status with PowerShell

Image courtesy of Serge Melki

I needed to find a quick way to see which hypervisor was installed.  I bounce between different development machines and some have Hyper-V enabled and some have Intel’s HAXM driver installed.  Both assist with virtual machines, but they can’t be used together.  I used to be 100% Hyper-V with running virtual machines and Android emulators.  The Microsoft Android Emulator used to be very good, but is suffering from a fair amount of bit rot.  In the meanwhile, Google’s Android Emulator has gone from being a great of sitting and watching something load very slowly to a tool that that you can use in real time.

Microsoft’s Android Emulator requires Hyper-V and Google’s Emulator really needs HAXM in order to have any level of performance.  Since I bound around from machine to machine (with the occasional repave), I wanted a quick way to see which hypervisor is installed.  Hyper-V requires a some work to turn on and off. HAXM is a kernel driver.  So I wrote a quick PowerShell script to report the status of each Hypervisor

$services = 'intelhaxm', 'vmicheartbeat'

$d = [System.ServiceProcess.ServiceController]::GetDevices() | ? {
  $services -contains $_.Name
}

$s = Get-Service | ? {
  $services -contains $_.Name
}

$d
$s

The first line just defines an array of names to match one. The next block of code uses GetDevices() to return the status of the HAXM driver. The block that follows returns the status of the Hyper-V Heartbeat Service. The last part just dumps out the results.

An alternative way is to pass the service name to Get-Service and it will return the status for the specified service. The problem is that it will error out if the specified service does not exist. And while that error message is a status report, it’s an ugly way to get that information

I named the script “hyper-stat.ps1” and when I run it on a machine with HAXM running, I get the following output

.\hyper-stat.ps1

Status   Name               DisplayName                           
------   ----               -----------                           
Running  IntelHaxm          Intel HAXM Service 

On a machine with Hyper-V and no HAXM, I get this

.\hyperv-stat.ps1

Status   Name               DisplayName                           
------   ----               -----------                           
Running  vmicheartbeat      Hyper-V Heartbeat Service    

If I disable Hyper-V, I would get the following:

.\hyperv-stat.ps1

Status   Name               DisplayName                           
------   ----               -----------                           
Stopped  vmicheartbeat      Hyper-V Heartbeat Service             

There are few ways of scripting this task. This one was simple and I have it on the machines that I use for coding.

Edit: Right after posting this, I realized it didn’t actually work. I was originally reporting on the status of vmms, the Hyper-V Virtual Machine Management Service. If Hyper-V is installed, that service will always be running, even when Hyper-V is not enabled. The Hyper-V Heartbeat service is a better test for seeing if Hyper-V is enabled.

Time to repave (slightly) my work machine

After lunch on Wednesday, I rebooted my work PC and it did not come back.  ADB had somehow lost the ability to see my actual Android devices.  I had tried a few things and was at the “Have you turned it off and on again” step.  I shutdown it and restarted it.   Windows 10 was not very happy.  I got the light blue screen of death.  It had a useless QR code and the ever so helpful message “critical service failure” message.

After a few rounds of rebooting and trying the standard self-repair options, I surrendered and handed it over to our IT guy.  I pretty much knew what the end game would be, but decided to let someone handle it.  He did pretty much the same things that I did and we decided to let Windows reset itself.

Windows Reset is both a good thing and a bad thing.  The good thing is that it basically says that your current Windows OS is rubbish and it will install a fresh one.  One that will be hopefully less damaged than the one that you are currently using. Or in my case, not using.  All of your data files are left intact.  Or at least in the condition that they were in before the SS Minnow goes for a  three hour tour.

I’m not sure what the root cause of the problem was.  I was nearly out of space on the primary drive and it’s been my experience that Windows doesn’t behave well when it runs out of room.  I had rebooted the day before and it was just fine then.  Today I had updated the Android SDK and that pretty much chewed through the remaining free space on the primary drive.  I could have probably used used Mike Halsey’s help.  Mike Halsey has xray vision for this sort of thing.

I’m due for a new machine at work and we had ordered it the day before.  So there really wasn’t much point in completely repaving this machine.  I just needed to install the stuff that I would need for the week or so until the new machine comes in.  So it’s time to install the bare minimum I need to get what I need to work on for the next week or so.

Office 2016
We have Office 365 so this wasn’t an optional installation

Android Studio
While I do nearly all of my Android development with Xamarin, there are times where it’s useful run some code in Android Studio.

Visual Studio 2017
This is where the good stuff happens.  I installed the latest preview bits.  I usually leave the preview versions to virtual machines, but this machine will be in my hands for a week or too.

Visual Studio Code
I have a few projects that are firmware that have their own C compilers, but no IDE.  Visual Studio Code is turning into my text editor of choice.  I like the latest and greatest, so I always install the Insiders edition.

SQL Server 2016 Developer Edition and SQL Server 2017 Management Studio
I have data needs.

Chrome
It’s more useful to than Edge for most stuff.  I still use Edge, but most of the time I use Chrome.

Paint.Net
For making a quick hack of the Windows 10 background.  Why isn’t this bundled with Windows?

Spotify
Sometimes I need some music to help me concentrate.  I have the attention span of a mal-adjusted toddler, playing music with a good beat tends to keep me focused.

Since I installed Android Studio before Visual Studio, it installed the Android SDK and assorted tools first.  Visual Studio installs a second set and in a separate location.  Android Studio places it a user profile folder, Visual Studio in a Program Files x86 folder.  Since I’m using Intel’s HAXM kernel driver to accelerate Google’s Android emulator, I need to know which IDE’s Android SDK installed HAXM.  When I get the new machine, I’ll install the Android SDK first and set each IDE to use that SDK.

In the meantime, I’ll starting making a list of the tools that I need to install on a new machine.  There is considerable overlap with what I install on my Macbook these days, but there are still key differences.