我正在尝试编写一个PowerShell脚本来检查Windows可选功能以查看是否安装了Hyper-V。但是,我的代码不起作用。即使禁用了Hyper-V,脚本也会输出它已启用。如何检查是否使用PowerShell启用了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."
}
代码运行时没有错误。
总是很好地发布你得到的错误 – Paolof76
代码运行时没有错误。 –