Reputation: 129
I want to run my application on a virtual machine but I want to know about the underlying Virtualization layer Hyper-V , VPC(Windows/Microsoft Virtual PC), or VMware. If it is VPC i don't want to run my application. I tried to look around here but the solution presented using WMI on WIn32_BIOS/MotherBoard doesn't differentiate between Hyper-V and VPC. I tried to see the instuction set method mentioned in the codeproject too. Is there a way to identify between the two(Hyper-V/VPC)? I don't have Hyper-V setup to test but i have Virtual PC 2007.
Upvotes: 4
Views: 2321
Reputation: 2061
Here's a Script i developed to detect this functionality
Function Get-VMVirtualizationLayer{
$Manufacturer = (Get-WmiObject win32_computersystem).manufacturer
$model= (Get-WmiObject win32_computersystem).model
$biosversion = (Get-WmiObject win32_bios).version
if ($model -match "Virtual Machine")
{
Write-Output " Virtual Machine Running on Microsoft Virtualization Platform"
if ($biosversion -match "VRTUAL")
{
Write-Output " Virtual Machine Running on Hyper-V "
}
elseif ($biosversion -match "A M I")
{
Write-Output "Virtual Machine Running on Windows Virtual PC"
}
}
elseif ($model -match "VMware Virtual Platform")
{
Write-Output "Virtual Machine is Running on VMware Virtual Platform"
}
elseif ($model -match "VirtualBox")
{
Write-Output "Virtual Machine is Running on VirtualBox"
}
}
Get-VMVirtualizationLayer
Copy Paste this entire code in an powershell prompt on the virtual machine and it would let you know the virtualization platform
Or you can copy paste the entire code into an notepad and save it as Get-VMVirtualizationLayer.ps1
Once You Run the script you would get the required output, here's the scrit output when i ran it on my Virtual Machine hosted in Hyper-V :)
PS C:\INSTALL> .\Get-VMVirtualizationLayer.ps1
Virtual Machine Running on Microsoft Virtualization Platform
Virtual Machine Running on Hyper-V
PS C:\INSTALL>
Upvotes: 2