diff --git a/public/Copy-DbaDbTableData.ps1 b/public/Copy-DbaDbTableData.ps1 index 3ed8b1aba75..e42efc7cc04 100644 --- a/public/Copy-DbaDbTableData.ps1 +++ b/public/Copy-DbaDbTableData.ps1 @@ -326,7 +326,12 @@ function Copy-DbaDbTableData { process { if ((Test-Bound -Not -ParameterName InputObject) -and ((Test-Bound -Not -ParameterName SqlInstance, Database -And) -or (Test-Bound -Not -ParameterName Table, View))) { - Stop-Function -Message "You must pipe in a table or specify SqlInstance, Database and [View|Table]." + if (Test-Bound -ParameterName Query) { + # Without the hint at Query the message reads as if SqlInstance or Database were missing (see #10676). + Stop-Function -Message "When using Query, you still have to specify SqlInstance, Database and [View|Table]. The query determines the data that is copied, but the command needs the table or view as the source object for its metadata." + } else { + Stop-Function -Message "You must pipe in a table or specify SqlInstance, Database and [View|Table]." + } return } diff --git a/tests/Copy-DbaDbTableData.Tests.ps1 b/tests/Copy-DbaDbTableData.Tests.ps1 index cbeb260bdaa..aa65b0a358d 100644 --- a/tests/Copy-DbaDbTableData.Tests.ps1 +++ b/tests/Copy-DbaDbTableData.Tests.ps1 @@ -116,6 +116,20 @@ Describe $CommandName -Tag IntegrationTests { $result = Copy-DbaDbTableData -SqlInstance $TestConfig.InstanceCopy2 -Database tempdb -Table dbo.dbatoolsci_example4 -Query "SELECT TOP (1) Id FROM tempdb.dbo.dbatoolsci_example4 ORDER BY Id DESC" -DestinationTable dbatoolsci_example3 -Truncate $result.RowsCopied | Should -Be 1 } + + It "Points at the Query requirement when Query is used without a source table" { + # The generic message reads as if SqlInstance or Database were missing (#10676). + $splatQueryOnly = @{ + SqlInstance = $TestConfig.InstanceCopy2 + Database = "tempdb" + Query = "SELECT TOP (1) Id FROM dbo.dbatoolsci_example4" + DestinationTable = "dbatoolsci_example3" + WarningAction = "SilentlyContinue" + } + $result = Copy-DbaDbTableData @splatQueryOnly + $result | Should -BeNullOrEmpty + $WarnVar | Should -Match "When using Query" + } } Context "When testing pipeline functionality" {