File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments