我想查找windows操作系统是托管在物理机还是虚拟机上,网上有一段powershell脚本,我添加了一些条件来识别机器是托管在云端(那么可能是虚拟机)。
在互联网上有一段powershell脚本,我在其中添加了一些条件来识别机器是否托管在云端(那么它可能是虚拟机)。
function GetMachineType {
$ComputerSystemInfo = Get-WmiObject -Class Win32_ComputerSystem
switch ($ComputerSystemInfo.Model) {
# Check for VMware Machine Type
"VMware Virtual Platform" {
Write-Output "This Machine is Virtual on VMware Virtual Platform."
Break
}
# Check for Oracle VM Machine Type
"VirtualBox" {
Write-Output "This Machine is Virtual on Oracle VM Platform."
Break
}
default {
switch ($ComputerSystemInfo.Manufacturer) {
# Check for Xen VM Machine Type
"Xen" {
Write-Output "This Machine is Virtual on Xen Platform"
Break
}
# Check for KVM VM Machine Type
"QEMU" {
Write-Output "This Machine is Virtual on KVM Platform."
Break
}
# Check for Hyper-V Machine Type
"Microsoft Corporation" {
if (get-service WindowsAzureGuestAgent -ErrorAction SilentlyContinue) {
Write-Output "This Machine is Virtual on Azure Platform"
}
else {
Write-Output "This Machine is Virtual on Hyper-V Platform"
}
Break
}
# Check for Google Cloud Platform
"Google" {
Write-Output "This Machine is Virtual on Google Cloud."
Break
}
# Check for AWS Cloud Platform
default {
if ((((Get-WmiObject -query "select uuid from Win32_ComputerSystemProduct" | Select-Object UUID).UUID).substring(0, 3) ) -match "EC2") {
Write-Output "This Machine is Virtual on AWS"
}
# Otherwise it is a physical Box
else {
Write-Output "This Machine is Physical Platform"
}
}
}
}
}
}
下面的注册表键只有在虚拟机在 HYPER-V 上时才会提供信息。
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Virtual Machine/Guest/Parameters*。
我想知道,是否有任何通用的方法可以通过编程找出windows操作系统是托管在物理机还是虚拟机上。
$IsVirtual=((Get-WmiObject win32_computersystem).model -eq 'VMware Virtual Platform' -or ((Get-WmiObject win32_computersystem).model -eq 'Virtual Machine'))
它将输出$True或$False扩展这个与其他虚拟模型制造商在你的房地产。