过滤掉同一行中相等的值?

问题描述 投票:0回答:1

我刚刚跑步

Get-DbaDbQueryStoreOption -SqlInstance <MySQLServer> | 
Where ActualState -ne DesiredState | 
Select Database, ActualState, DesiredState

我的目的是从

Get-DbaDbQueryStoreOption
获取所有行,其中
ActualState
DesiredState
不相同。令我惊讶的是,这返回了
ActualState
DesiredState
相同的行。

我的 PowerShell 是否有错误,或者这是

Get-DbaDbQueryStoreOption
中的错误?

我相信即使您对 dbatools 模块中的

Get-DbaDbQueryStoreOption
命令一无所知,这个问题也是有意义的。然而,
ActualState
DesiredState
的类型是
Selected.Microsoft.SqlServer.Management.Smo.QueryStoreOptions

arrays powershell string-comparison dbatools
1个回答
0
投票

假设

DesiredState
也指的是输入对象属性,将
Where ActualState -ne DesiredState
替换为:

Where { $_.ActualState -ne $_.DesiredState }

您尝试使用简化语法是行不通的,因为诸如

-ne
之类的运算符的右侧必须是文字变量引用表达式,并且它们都无法引用通过自动$_变量
当前管道输入对象
,因为后者仅在脚本块内可用。

© www.soinside.com 2019 - 2024. All rights reserved.