0

The following script searches deletes statements in SSIS. These delete statements came from sql cache for some reason they came back with "]" missing. This missing brace is causing my select object to fail see error below. I cant remove braces before search else it will not find matches but leaving it on is causing issues with selection. Is there a way to ignore these braces during the select object. If the delete does not have any braces the script works like a charm.

$SearchStrings = Get-Content "C:\Users\someuser\Desktop\DataDumps_PS\Delete_input.txt"
$out_file = "C:\Users\someuser\Desktop\DataDumps_PS\Deletes$(get-date -f yyyyMMdd).txt"

$RootString = "E:\SSIS_packages\"
Foreach($SearchString in $SearchStrings){
Write-host $SearchString
                                        
Get-ChildItem $RootString -recurse | Select-String -pattern $SearchString | group path | 
Select-Object name,@{name="SearchString";expression={$SearchString.replace('[','').replace(']','')}}  | Export-Csv $out_file - 
append -NoTypeInformation -Force #select name, "$SearchString"
}

Error for deletes that have a missing brace.

Select-String : The string DELETE FROM [dbo].[APP_DMEVS_STG is not a valid regular 
expression: parsing "DELETE FROM [dbo].[APP_DMEVS_STG" - Unterminated [] set.
Leo Torres
  • 673
  • 1
  • 6
  • 18

1 Answers1

1

Sounds like it's failing on interpreting it as a regular expression. Try replacing this

Select-String -pattern $SearchString

with this

Select-String -SimpleMatch "$SearchString"
Seb
  • 179
  • 2
  • 6
  • I replaced it with. Get-ChildItem $RootString -recurse | Select-String -pattern $SearchString | group path | Select-Object name,@{name="SearchString";expression={$($SearchString.replace('[','')).replace(']','')}} | Export-Csv $out_file -append -NoTypeInformation -Force #select name, "$SearchString" still same error. – Leo Torres Sep 30 '21 at 19:21
  • The last change -simplematch worked no errors thank you! – Leo Torres Oct 01 '21 at 13:23