I'm trying to find the multi line string in the text file using below script but it's not working as expected.
$tns= "MYSID=
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = mydnshostname)(PORT = 1111))
)
(CONNECT_DATA =
(SERVICE_NAME = MYSID)
)
)"
$SEL = Select-String -Path T:\Test\search.txt -Pattern $tns
if ($SEL -ne $null)
{
Write-Host "Contains String"
}
else
{
Write-Host "Not Contains String"
}
Select-String, the-Patternis a regex pattern. your pattern contains multiple special regex chars [()for instance]. try using-SimpleMatchto get a non-regex pattern match.Select-String ... -Pattern $([regex]::Escape($tns))