2017-03-15 2 views
0

Where-Object cmdlet을 사용하여 데이터 집합을 필터링하려고합니다. 예를 들어 다음 cmdlet의 Notifications 열을 고려하십시오. 여기에는 두 개의 값이 포함되어 있으며 필터링하려면 Where-Object | {$_.Notifications -eq 'Operator1'}으로 필터링하고 싶습니다. 나는 또한 -in, -notin, -contains, -notcontains, -match, -notmatch, -like, -notlike 등을 사용하여 필터링하려고 시도했다. 그러나 이것들 중 어느 것도 지금까지 결과를 얻지 못했다. 모든 포인터는 매우 높이 평가됩니다.Where-Object cmdlet을 사용하여 데이터 집합 필터링

PS>Get-DbaAgentAlert -SqlInstance 'Redacted' 

ComputerName   : Redacted 
SqlInstance   : Redacted 
************   : ************ 
************   : ************ 
Notifications   : {Operator1, Operator2} 
************   : ************ 
************   : ************ 

지내요 Get-Member 반환

PS>Get-DbaAgentAlert -SqlInstance 'Redacted' | Get-Member 

    TypeName: System.Management.Automation.PSCustomObject 

Name     MemberType Definition 
----     ---------- ---------- 
OtherColumns   ********** *********** 
Notifications   NoteProperty DataTable Notifications= 

또한, Notifications 컬럼의 실제 데이터 집합

PS>$alerts.Notifications | Select -First 2 | Format-Table 

OperatorId OperatorName  UseEmail UsePager UseNetSend HasEmail HasPager HasNetSend 
---------- ------------  -------- -------- ---------- -------- -------- ---------- 
     1 Operator1   True False  False  True False  False 
     2 Operator2   True False  False  True False  False 

감사 같을 것이다!

편집 : 내가 여기에 사용하고이 cmdlet의 소스입니다

+0

당신이 봤어 객체 것이 올바른 요소를 대상으로해야'-contains'? 알림은 배열처럼 보입니다. – gvee

+0

예, 질문에 언급했습니다. 그러나 결과를 반환하지 않았습니다. 나는 여기서 사용하고있는 명령의 근원을 넣었어야했다. 이 모듈의 것입니다 - [dbatools] (0125) # – walt

+0

결과의 어떤 부분을 필터링하고 싶지는 않습니다. cmdlet은 일부 경고에 각각 여러 개의 값이 포함 된 알림을 포함하는 알림을 반환합니다. DataRow (Notifications DataTable의 단일 항목)와 문자열을 비교하려고 시도하면 물론 실패합니다. DataTable 열 (예 : "OperatorName")을 고려해야합니다. – TToni

답변

0

dbatools/Get-DbaAgentAlert에서하면이 시도 : 그 밖으로 어떻게 작동하는지

다음
Get-DbaAgentAlert -SqlInstance ".\sql2016" | 
Where-Object {$_.Notifications.OperatorName -eq "test1"} 

가있다 :

$results = Get-DbaAgentAlert -SqlInstance ".\sql2016" 
$res.Notifications 

이 수익을 예 :

OperatorId : 1 
OperatorName : test1 
UseEmail  : True 
UsePager  : False 
UseNetSend : False 
HasEmail  : False 
HasPager  : False 
HasNetSend : False 

OperatorId : 2 
OperatorName : test2 
UseEmail  : True 
UsePager  : False 
UseNetSend : False 
HasEmail  : False 
HasPager  : False 
HasNetSend : False 

... Notifications 속성이 기본적으로 또 다른 목적은, 그래서 우리는

+1

정말 관심을 기울여야합니다. 매우 감사합니다. 그게 효과가 있었어! – walt

관련 문제