windows - 确定 Windows 是托管在物理机上还是虚拟机上?#电源外壳
问题描述
我正在尝试查找 Windows 操作系统是否托管在物理机或虚拟机上。
互联网上有一个 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"
}
}
}
}
}
}
仅当 VM 位于 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 与您的房地产中的其他虚拟模型/制造商一起扩展它
推荐阅读
- android - 带有圆形轮廓图像视图的滚动活动
- google-cloud-platform - 设备何时向云/发布订阅报告状态?
- php - API 仅在一种情况下工作 - 使用 laravel
- reactjs - 如何更改视频的来源?
- excel - 使用用户创建的名称引用新创建的工作表上的单元格
- angular-material - 可在单个 Angular 项目中用于 Bootstrap 和 Angular 材料的 Material Design
- javascript - JS中的加载栏问题
- c# - 0 到枚举的隐式转换
- html - 如何在输入下创建带有两个按钮的搜索框?
- android - 蓝牙连接:MODE_IN_CALL 与 MODE_IN_COMMUNICATION