Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Problem with square bracket in replace command

$
0
0

Hi,

I am trying to do the following:

PS SQLSERVER:\SQL\MyServer\MyInstance\Databases\MyDB\Tables> $Search = "ON [WBC_" + $TableName

PS SQLSERVER:\SQL\MyServer\MyInstance\Databases\MyDB\Tables> $TableScriptFile = $TableScriptFile -replace $Search, $Replacement

I get the error below.  If I remove the square bracket, all works fine.

I've tried putting '' \\ ' \ before the square brackets, which made the script run, but I was getting those extra symbols in my string, which does not allow the script to function as intended, e.g.:

ON `[WBC_MyTable_ps`](`[PartitionDate`])

 

Any ideas?

Thanks.

 

Invalid regular expression pattern: ON [WBC_MyTable.

At line:1 char:45

+ $TableScriptFile = $TableScriptFile -replace <<<<  $Search, $Replacement

    + CategoryInfo          : InvalidOperation: (ON [WBC_MyTable:String) [], ParentContainsErrorRecordException

    + FullyQualifiedErrorId : InvalidRegularExpression


Viewing all articles
Browse latest Browse all 6937

Trending Articles