我正在尝试使用“Get-WMIObject”。
如果我运行脚本,它会以红色文本输出,而不是绿色,因为它应该基于if / else语句。此外,在脚本运行后,如果我键入$ PredictFailure,则表明$ PredictFailure为“False”。
屏幕截图显示正在发生的事情。
$PredictFailure = Get-WmiObject -namespace root\wmi –class MSStorageDriver_FailurePredictStatus | Select-Object PredictFailure
Foreach ($D in $PredictFailure)
{
$PredictFailure = $D.PredictFailure
If ($D.PredictFailure -eq "False")
{Get-WmiObject -namespace root\wmi –class MSStorageDriver_FailurePredictStatus -ComputerName $env:computername | Select-Object PSComputerName, Active, PredictFailure, Reason | Format-Table -AutoSize | Out-String | Write-Host -ForegroundColor Green}
Else
{Get-WmiObject -namespace root\wmi –class MSStorageDriver_FailurePredictStatus -ComputerName $env:computername | Select-Object PSComputerName, Active, PredictFailure, Reason | Format-Table -AutoSize | Out-String | Write-Host -ForegroundColor Red}
}
答案 0 :(得分:0)
您正在与字符串" False"进行比较。使用$FALSE
引用布尔常量false:
If ($D.PredictFailure -eq $FALSE)
或使用否定
If (-not $D.PredictFailure)