Skip to content

Commit 14a47a2

Browse files
Export-DbaCsv, Export-DbaDacPackage - Normalize table/schema names via Get-ObjectNameParts (#10314)
1 parent 241a118 commit 14a47a2

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

public/Export-DbaCsv.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,14 @@ function Export-DbaCsv {
288288
if ($PSBoundParameters.Query) {
289289
$sqlToExecute = $Query
290290
} elseif ($PSBoundParameters.Table) {
291-
# Parse table name for schema
292-
if ($Table -match "^(.+)\.(.+)$") {
293-
$schemaName = $Matches[1]
294-
$tableName = $Matches[2]
291+
# Parse table name for schema using Get-ObjectNameParts to correctly handle bracketed names like [Gross.Table.Name]
292+
$nameParts = Get-ObjectNameParts -ObjectName $Table
293+
if ($nameParts.Schema) {
294+
$schemaName = $nameParts.Schema
295295
} else {
296296
$schemaName = "dbo"
297-
$tableName = $Table
298297
}
298+
$tableName = $nameParts.Name
299299
$sqlToExecute = "SELECT * FROM [$schemaName].[$tableName]"
300300
}
301301

public/Export-DbaDacPackage.ps1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,14 @@ function Export-DbaDacPackage {
184184
if ($Table) {
185185
$tblList = New-Object 'System.Collections.Generic.List[Tuple[String, String]]'
186186
foreach ($tableItem in $Table) {
187-
$tableSplit = $tableItem.Split('.')
188-
if ($tableSplit.Count -gt 1) {
189-
$tblName = $tableSplit[-1]
190-
$schemaName = $tableSplit[-2]
187+
# Use Get-ObjectNameParts to correctly handle bracketed names like [Gross.Table.Name]
188+
$nameParts = Get-ObjectNameParts -ObjectName $tableItem
189+
if ($nameParts.Schema) {
190+
$schemaName = $nameParts.Schema
191191
} else {
192-
$tblName = [string]$tableSplit
193-
$schemaName = 'dbo'
192+
$schemaName = "dbo"
194193
}
195-
$tblList.Add((New-Object "tuple[String, String]" -ArgumentList $schemaName, $tblName))
194+
$tblList.Add((New-Object "tuple[String, String]" -ArgumentList $schemaName, $nameParts.Name))
196195
}
197196
} else {
198197
$tblList = $null

0 commit comments

Comments
 (0)