我正在尝试使用“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}
}