Powershell -match and weird results -


I have a problem with the conditional statement in the strengths with the -mail feature.

Say I have 3 files:

Test.dll (this is the word [TestClass] in dll)

Test1 Dll ( TestClass is without parentheses in this DLL)

Test2 DLL (this is not DLL at all)

I am searching for files whose If I use the following code, both Test.dll and Test1.dll work in this situation: (By the way, every $ _ is a DLL)

  if ([IO.File] :: readAllText ($ _) -Match "TestClass") {$ ProjectTestContainers + = $ _ Write-Host $ ProjectTestContainers}  

Which should do it, but it's not what I want. I only want the files with [TestClass] , so I tried to do it

  if ([IO.File] :: ReadAllText ($ _) - Mail "[[TestClass`]") {$ ProjectTestContainers + = $ _ Write-Host $ ProjectTestContainers}  

All these conditions, Test.dll, Test1.dll and Test2.dll, which It should not. This should give me only test.dll because it is the only one that has [TestClass]

any idea? Tell me that you need more than me.

-mail operator is a regular expression with your 'test class' string Because the bracket (`) character is not the true escape character for the regular expression pattern, you think that the bracket characters are in need of escape, because these regular expressions are special characters in the pattern because we are using regex Working, the true escape character is '\'; Try it instead:

  if ([IO.File] :: ReadAllText ($ _) -mail "\ [TestClass \]")  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -