title: If / Else statement using Get-WMIObject
body: <p>I am attempting to use “Get-WMIObject”. </p>
  
  <p>If I run the script it outputs in a red text, not green as it should based on the if/else statement. Furthermore, after the script has run if I type $PredictFailure it shows that $PredictFailure is “False”.</p>
  
  <p>Screenshot to show what is going on.</p>
  
  <p><a href="https://i.stack.imgur.com/TGCFm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TGCFm.png" alt="enter image description here"></a></p>
  
  <pre><code>$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}
  
  }
  </code></pre>