Before submitting a bug report:
Steps to Reproduce
Copy-DbaDbTableData doesn't copy to correct table if there are >1 schema with the same table name, and you are trying to copy a table that is not the first schema alphabetically.

Expected Behavior
Both the top and bottom call would write to ww schema version of table.
Actual Behavior
If you do not specify a destinationTable explicitly, the code sets (246-248)
if ((Test-Bound -Not -ParameterName DestinationTable)) {
$DestinationTable = $sqltable.Name
}
Then it calls this: (230)
$desttable = Get-DbaDbTable -SqlInstance 'useomdbn12048,1113' -Table $DestinationTable -Database $Database -EnableException -Verbose:$false | Select-Object -First 1
What happens is that since $sqltable.Name is just the table name, and does not include the schema, the | Select-Object -First 1 ends up pulling the first schema alphabetically with this table name.
I believe the fix would be to change the $DestinationTable = $sqltable.Name line to append the schem name from the $sqltable object as well:
so line 247 would become this:
$DestinationTable = $sqltable.Schema + '.' + $sqltable.Name;
At this point you can likely remove the | Select-Object -First 1 also
Environmental data
PowerShell:
Name Value
PSVersion 5.1.14393.2430
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2430
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
SQL Server:
Microsoft SQL Server 2012 (SP1) - 11.0.3156.0 (X64) May 4 2015 18:48:09 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.2 (Build 9200: )
Before submitting a bug report:
powershell -NoProfile)Steps to Reproduce
Copy-DbaDbTableData doesn't copy to correct table if there are >1 schema with the same table name, and you are trying to copy a table that is not the first schema alphabetically.
Expected Behavior
Both the top and bottom call would write to ww schema version of table.
Actual Behavior
If you do not specify a destinationTable explicitly, the code sets (246-248)
Then it calls this: (230)
What happens is that since
$sqltable.Nameis just the table name, and does not include the schema, the| Select-Object -First 1ends up pulling the first schema alphabetically with this table name.I believe the fix would be to change the
$DestinationTable = $sqltable.Nameline to append the schem name from the$sqltableobject as well:so line 247 would become this:
At this point you can likely remove the
| Select-Object -First 1alsoEnvironmental data
PowerShell:
Name Value
PSVersion 5.1.14393.2430
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2430
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
SQL Server:
Microsoft SQL Server 2012 (SP1) - 11.0.3156.0 (X64) May 4 2015 18:48:09 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.2 (Build 9200: )