@@ -163,30 +163,36 @@ function Invoke-DbaDbDbccUpdateUsage {
163163 try {
164164 $query = $StringBuilder.ToString ()
165165 if (Test-Bound - ParameterName Table) {
166- if ($Table -notmatch ' ^\d+$' ) {
166+ if ($Table -notmatch " ^\d+$" ) {
167167 $tableNameParts = Get-ObjectNameParts - ObjectName $Table
168- if ($tableNameParts.Schema ) {
169- $tableIdentifier = " [$ ( $tableNameParts.Schema ) ].[$ ( $tableNameParts.Name ) ]"
168+ if ($tableNameParts.Name ) {
169+ $escapedTableName = $tableNameParts.Name.Replace (" ]" , " ]]" )
170+ if ($tableNameParts.Schema ) {
171+ $escapedTableSchema = $tableNameParts.Schema.Replace (" ]" , " ]]" )
172+ $tableIdentifier = " [$escapedTableSchema ].[$escapedTableName ]"
173+ } else {
174+ $tableIdentifier = " [$escapedTableName ]"
175+ }
170176 } else {
171- $tableIdentifier = " [ $ ( $tableNameParts .Name ) ] "
177+ $tableIdentifier = $Table
172178 }
173179 }
174180 if (Test-Bound - ParameterName Index) {
175- if ($Table -match ' ^\d+$' ) {
176- if ($Index -match ' ^\d+$' ) {
181+ if ($Table -match " ^\d+$" ) {
182+ if ($Index -match " ^\d+$" ) {
177183 $query = $query.Replace (' #options#' , " '$ ( $db.name ) ', $Table , $Index " )
178184 } else {
179185 $query = $query.Replace (' #options#' , " '$ ( $db.name ) ', $Table , '$Index '" )
180186 }
181187 } else {
182- if ($Index -match ' ^\d+$' ) {
188+ if ($Index -match " ^\d+$" ) {
183189 $query = $query.Replace (' #options#' , " '$ ( $db.name ) ', '$tableIdentifier ', $Index " )
184190 } else {
185191 $query = $query.Replace (' #options#' , " '$ ( $db.name ) ', '$tableIdentifier ', '$Index '" )
186192 }
187193 }
188194 } else {
189- if ($Table -match ' ^\d+$' ) {
195+ if ($Table -match " ^\d+$" ) {
190196 $query = $query.Replace (' #options#' , " '$ ( $db.name ) ', $Table " )
191197 } else {
192198 $query = $query.Replace (' #options#' , " '$ ( $db.name ) ', '$tableIdentifier '" )
0 commit comments