【发布时间】:2016-06-01 11:40:14
【问题描述】:
我正在尝试编写一个 PowerShell 脚本来检查 Windows 可选功能以查看是否安装了 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."
}
代码运行时没有错误。
【问题讨论】:
-
最好也发布您遇到的错误
-
代码运行时没有报错。
-
=仅用于在 PowerShell 中存储值。要进行is equal to比较,您必须使用-eq语法。
标签: windows powershell hyper-v