From abf7cd6c2e454e96e99ffcb8e00981bc41019943 Mon Sep 17 00:00:00 2001 From: Andreas Jordan Date: Tue, 3 Oct 2023 20:38:18 +0200 Subject: [PATCH] Correct filtering for listener names (do Get-DbaAgListener) --- public/Get-DbaAgListener.ps1 | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/public/Get-DbaAgListener.ps1 b/public/Get-DbaAgListener.ps1 index 075cc6ce2d..4fc520c6f7 100644 --- a/public/Get-DbaAgListener.ps1 +++ b/public/Get-DbaAgListener.ps1 @@ -76,19 +76,20 @@ function Get-DbaAgListener { $InputObject += Get-DbaAvailabilityGroup -SqlInstance $SqlInstance -SqlCredential $SqlCredential -AvailabilityGroup $AvailabilityGroup } + $agListeners = $InputObject.AvailabilityGroupListeners if (Test-Bound -ParameterName Listener) { - $InputObject = $InputObject | Where-Object { $_.AvailabilityGroupListeners.Name -contains $Listener } + $agListeners = $agListeners | Where-Object { $Listener -contains $_.Name } } $defaults = 'ComputerName', 'InstanceName', 'SqlInstance', 'AvailabilityGroup', 'Name', 'PortNumber', 'ClusterIPConfiguration' - foreach ($aglistener in $InputObject.AvailabilityGroupListeners) { - $server = $aglistener.Parent.Parent - Add-Member -Force -InputObject $aglistener -MemberType NoteProperty -Name ComputerName -value $server.ComputerName - Add-Member -Force -InputObject $aglistener -MemberType NoteProperty -Name InstanceName -value $server.ServiceName - Add-Member -Force -InputObject $aglistener -MemberType NoteProperty -Name SqlInstance -value $server.DomainInstanceName - Add-Member -Force -InputObject $aglistener -MemberType NoteProperty -Name AvailabilityGroup -value $aglistener.Parent.Name - Select-DefaultView -InputObject $aglistener -Property $defaults + foreach ($agListener in $agListeners) { + $server = $agListener.Parent.Parent + Add-Member -Force -InputObject $agListener -MemberType NoteProperty -Name ComputerName -value $server.ComputerName + Add-Member -Force -InputObject $agListener -MemberType NoteProperty -Name InstanceName -value $server.ServiceName + Add-Member -Force -InputObject $agListener -MemberType NoteProperty -Name SqlInstance -value $server.DomainInstanceName + Add-Member -Force -InputObject $agListener -MemberType NoteProperty -Name AvailabilityGroup -value $agListener.Parent.Name + Select-DefaultView -InputObject $agListener -Property $defaults } } } \ No newline at end of file