Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
意識的に PowerShell の投稿を増やしております。まだ Windows PowreShell 未経験のみなさん、始めるなら今ですよ!
さて、さまざまな場面に PowerShell が浸透しつつありますし、今後もそれが加速するわけですが、最も基本的なシチュエーションの1つに「仮想環境」か「物理環境」かを識別したい...という場合があります。
最も簡単な方法は、WMI に用意されている win32_computersystem です。
WMI に拒絶反応を示す方もいらっしゃるかもしれませんが、使い方は超簡単です。
PowerShell コンソールから以下のように入力してください。
| PS C:\> (get-wmiobject win32_computersystem).model Virtual Machine |
上記は Hyper-V 上の仮想マシン上で実行した結果です。結果もシンプルです。
物理マシン上で実行すると以下のような答えが返されます。
PS C:\> (get-wmiobject win32_computersystem).model 4270CTO |
「4270CTO」って何ぞや?
これは、物理マシンのモデル名ですね。
物理マシンか仮想マシンかを判断するのであれば、このように win32_computersystem の回答が「Virtual Machine」かどうかを判断すれば OK です。
え?Virtual PC か Hyper-V かを見分けたい???
できなくはありません。それについては次回。