我正在尝试查找 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" …Run Code Online (Sandbox Code Playgroud)