首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >确定Windows是托管在物理机器还是虚拟机上?#Powershell

确定Windows是托管在物理机器还是虚拟机上?#Powershell
EN

Stack Overflow用户
提问于 2019-12-26 14:39:40
回答 1查看 7.6K关注 0票数 3

我试图找出windows操作系统是托管在物理机器上还是在虚拟机上。

internet上有一个powershell脚本片段,我在其中添加了几个条件来确定机器是否托管在云上(然后它可能是虚拟机)。

代码语言:javascript
复制
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位于超级V上时才会提供信息。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual机器\来宾\参数*

我想知道是否有任何通用的方法来通过编程来找出windows OS是托管在物理机器还是虚拟机上。

EN

回答 1

Stack Overflow用户

发布于 2020-05-27 07:59:32

代码语言:javascript
复制
    $IsVirtual=((Get-WmiObject win32_computersystem).model -eq 'VMware Virtual Platform' -or ((Get-WmiObject win32_computersystem).model -eq 'Virtual Machine'))

它将输出$True或$False,将其扩展到您所在领域中的其他虚拟模型/制造商。

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59489885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档