Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion public/Get-DbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ function Get-DbaDatabase {
begin {

if ($ExcludeUser -and $ExcludeSystem) {
Stop-Function -Message "You cannot specify both ExcludeUser and ExcludeSystem." -Continue -EnableException $EnableException
# No -Continue here: the begin block has no enclosing loop, so the continue would escape
# the command and eat an iteration of whatever loop the caller runs in.
Stop-Function -Message "You cannot specify both ExcludeUser and ExcludeSystem." -EnableException $EnableException
return
}

}
Expand Down
15 changes: 15 additions & 0 deletions tests/Get-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ Describe $CommandName -Tag IntegrationTests {
}
}

Context "When ExcludeUser and ExcludeSystem are combined" {
It "Warns without eating an iteration of the caller's loop" {
# The invalid combination used to run Stop-Function -Continue in the begin block, where no
# loop encloses it - the continue escaped the command and consumed an iteration of this
# very loop, so the counter stayed at zero.
$loopCount = 0
foreach ($i in 1..3) {
$null = Get-DbaDatabase -SqlInstance $TestConfig.InstanceSingle -ExcludeUser -ExcludeSystem -WarningAction SilentlyContinue
$loopCount++
}
$loopCount | Should -Be 3
$WarnVar | Should -BeLike "*You cannot specify both ExcludeUser and ExcludeSystem*"
}
}

}

Describe $CommandName -Tag IntegrationTests {
Expand Down