PowerShell: filter string list

This seems like a very simple thing, but I'm new to PowerShell and can't figure it out or find an example on the web ...

I am trying to filter a list of strings. This list of strings is the result of the svn list command (a list of Subversion repository files), for example:

svn list -R PATHTOREPOSITORY

I've tried

svn list -R PATHTOREPOSITORY | where {$_ -like "stringtomatch"}

and it does not work. How can i fix this?

+7
source share
2 answers

You might want to use -match instead of -like. -Match is more powerful (based on regex) and will work as you expected:

svn list -R PATHTOREPOSITORY | where {$_ -match 'stringtomatch'} 
+16
source

Using:

svn list -R PATHTOREPOSITORY | where {$_ -like "*stringtomatch*"}
+6
source

All Articles