我想用“Get-WMIObject”。
如果我运行脚本,它输出的是红色文本,而不是应该基于If / not语句的绿色。此外,在脚本运行之后,如果我输入$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}
}发布于 2018-02-19 22:13:14
您正在与字符串"False“进行比较。使用$FALSE引用布尔常量false:
If ($D.PredictFailure -eq $FALSE)或使用否定
If (-not $D.PredictFailure)https://stackoverflow.com/questions/48874793
复制相似问题