Skip to content

Commit

Permalink
bug fix 9068
Browse files Browse the repository at this point in the history
  • Loading branch information
sqlarticles authored Sep 8, 2023
1 parent 432aebd commit 3a32d5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion public/New-DbaDbUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ function New-DbaDbUser {
$getDbParam.OnlyAccessible = $True
if ($Database) {
$getDbParam.Database = $Database
} elseif (-not $IncludeSystem) {
}
if (-not $IncludeSystem) {
$getDbParam.ExcludeSystem = $True
}
if ($ExcludeDatabase) {
Expand All @@ -169,6 +170,11 @@ function New-DbaDbUser {
$databases = Get-DbaDatabase @getDbParam
$getValidSchema = Get-DbaDbSchema -InputObject $databases -Schema $DefaultSchema -IncludeSystemSchemas

#This block is required so that correct error message can be returned to the user when incorrect database name is given or the database doesn't exists in the server.
if (-not $Database) {
$Database = $databases
}

foreach ($db in $Database) {
$dbSmo = $databases | Where-Object Name -eq $db

Expand Down
6 changes: 6 additions & 0 deletions tests/New-DbaDbUser.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,11 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
$results.Name | Should -Be $loginName, $loginName, $loginName
$results.DefaultSchema | Should -Be dbo, dbo, dbo
}

It "Should add user to all user databases" {
$results = New-DbaDbUser -SqlInstance $script:instance2 -Login $loginName -Force -EnableException
$results.Count | Should -Be 3
$results.Name | Get-Unique | Should -Be $loginName
}
}
}

0 comments on commit 3a32d5e

Please sign in to comment.