加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

windows – 如何检查是否使用PowerShell启用了Hyper-V?

发布时间:2020-12-14 02:49:11 所属栏目:Windows 来源:网络整理
导读:我正在尝试编写一个Power Shell脚本来检查 Windows可选功能,以查看是否安装了Hyper-V.但是,我的代码无效.即使禁用Hyper-V,脚本也会输出已启用的Hyper-V. #Requires -RunAsAdministrator# Get the Hyper-V feature and store it in $hyperv$hyperv = Get-Wind
我正在尝试编写一个Power Shell脚本来检查 Windows可选功能,以查看是否安装了Hyper-V.但是,我的代码无效.即使禁用Hyper-V,脚本也会输出已启用的Hyper-V.

#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条件有关,试试这个:

if($hyperv.State -eq "Enabled")

=符号不起作用,你需要以PowerShell的方式做

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读