首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >If /Get语句使用Get-WMIObject

If /Get语句使用Get-WMIObject
EN

Stack Overflow用户
提问于 2018-02-19 21:57:12
回答 1查看 1.7K关注 0票数 0

我想用“Get-WMIObject”。

如果我运行脚本,它输出的是红色文本,而不是应该基于If / not语句的绿色。此外,在脚本运行之后,如果我输入$PredictFailure,它就会显示$PredictFailure是“False”。

截图来显示正在发生的事情。

代码语言:javascript
复制
$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}

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-19 22:13:14

您正在与字符串"False“进行比较。使用$FALSE引用布尔常量false:

代码语言:javascript
复制
If ($D.PredictFailure -eq $FALSE)

或使用否定

代码语言:javascript
复制
If (-not $D.PredictFailure)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48874793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档