Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-DbaServerRoleMember - Fix Login parameter being overwritten #8496

Merged
merged 4 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions functions/Get-DbaServerRoleMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,17 @@ function Get-DbaServerRoleMember {
}

foreach ($member in $members) {
$login = $server.Logins | Where-Object { $_.Name -eq $member }
$loginList = $server.Logins | Where-Object { $_.Name -eq $member }

if ($login) {
[PSCustomObject]@{
ComputerName = $server.ComputerName
InstanceName = $server.ServiceName
SqlInstance = $server.DomainInstanceName
Role = $role.Name
Name = $login.Name
Name = $loginList.Name
SmoRole = $role
SmoLogin = $login
SmoLogin = $loginList
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Get-DbaServerRoleMember.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
$testLogin = 'getDbaInstanceRoleMemberLogin'
$null = New-DbaLogin -SqlInstance $instance -Login $testLogin -Password $password1
$null = Set-DbaLogin -SqlInstance $instance -Login $testLogin -AddRole 'dbcreator'

$instance1 = Connect-DbaInstance -SqlInstance $script:instance1
$null = New-DbaLogin -SqlInstance $instance1 -Login $testLogin -Password $password1
$null = Set-DbaLogin -SqlInstance $instance1 -Login $testLogin -AddRole 'dbcreator'
}

Context "Functionality" {
Expand Down Expand Up @@ -59,6 +63,13 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" {
$uniqueLogins.Count | Should -BeExactly 1
$uniqueLogins | Should -Contain $testLogin
}

It 'Returns results for all instances' {
$result = Get-DbaServerRoleMember -SqlInstance $instance, $instance1 -Login $testLogin

$uniqueInstances = $result.SqlInstance | Select-Object -Unique
$uniqueInstances.Count | Should -BeExactly 2
}
}

AfterAll {
Expand Down