如何检查是否使用PowerShell启用了Hyper-V? [英] How do you check to see if Hyper-V is enabled using PowerShell?
本文介绍了如何检查是否使用PowerShell启用了Hyper-V?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图编写一个PowerShell脚本来检查Windows可选功能,以查看是否安装了Hyper-V.但是,我的代码无法正常工作.即使在禁用Hyper-V的情况下,脚本也会输出已启用的信息.
I am trying to write a PowerShell script that checks the Windows Optional Features to see if Hyper-V is installed. However, my code is not working. Even when Hyper-V is disabled, the script outputs that it is already enabled.
#Requires -RunAsAdministrator
# Get the Hyper-V feature and store it in $hyperv
$hyperv = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online
# Check if Hyper-V is already enabled.
if($hyperv.State = "Enabled") {
Write-Host "Hyper-V is already enabled."
} else {
Write-Host "Hyper-V is disabled."
}
运行代码时没有错误.
推荐答案
我认为这与您的if
条件有关,请尝试以下操作:
I believe it has to do with your if
condition, try this:
if($hyperv.State -eq "Enabled")
=
标志不起作用,您需要以PowerShell方式进行操作
The =
sign is not going to work, you need to do it PowerShell way
这篇关于如何检查是否使用PowerShell启用了Hyper-V?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文