I'm stuck with a regex issue. I have a text file that has lots of application names with different random characters in the beginning of it and the end of it. Some applications have parentheses to show the bit version of it (x64) and (x86). I go thru each application, take the name and pass it to my function. From there I compare it with another text file to see if it has "OK" as it's installed. However, my function uses a regex and when I pass my application name for comparison, it just fails since parentheses are regex characters. here is my function
function Get_End($Application)
{
$EndRegex = [regex]"($Application).*(END OK)"
try
{
$result = Get-Content "C:\temp\test.log" | Where-Object{ $_ -Match
$EndRegex }
if($result -eq $null)
{
return "Not Found"
}
else
{
return $Matches[2]
}
}
catch
{
Return "ERROR"
}
}
And this is how I pass my variable name:
Get_End($ApplicationName)
I tried putting $ in front uses {} instead of () in my function with no luck.
Anyone know how to get around this?
Thanks in advance!