lundi 19 février 2018

If / Else statement using Get-WMIObject

I am new to PowerShell and I cannot for the life of me figure out why the script below is not working properly. I have very similar scripts but they are not calling any WMIObjects As soon as I attempt to “Get-WMIObject” I have run into problems.

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 in fact “False”. Have included a screenshot below to show you what is going on.

Thanks in advance for any and all suggestions

$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}

} enter image description here

Aucun commentaire:

Enregistrer un commentaire