header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

difference between like and contains
Last Post 05 Feb 2008 03:04 PM by bsonposh. 4 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
kctalbotUser is Offline
New Member
New Member
Posts:14
Avatar

--
04 Feb 2008 05:24 PM  

Going through a file I was trying to select lines that only contain "teamsites".  I tried piping file through where-object { $_ -contains "teamsites"} and got nothing whether or not I used wildcard "*" before or after "*teamsites*  or both.  Using -like selected the lines I wanted, but I have gone through text and help files without seeing why.

To just further confuse myself I also tried $_.contains("teamsites";) and that just got syntax errors.  Shouldn't that work?

jdelatorreUser is Offline
New Member
New Member
Posts:18
Avatar

--
04 Feb 2008 06:31 PM  
This might help.

http://www.computerperformance.co.uk/powershell/powershell_conditional_operators.htm
Joel D.
bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
04 Feb 2008 06:32 PM  
-like = Wildcard match
-contains = is an containment operator for Arrays. Checks to see if the array "CONTAINS" the value.
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
smurawskiUser is Offline
New Member
New Member
Posts:46

--
04 Feb 2008 08:19 PM  
You could try Select-String --

Select-String -path 'path to your file' -text 'teamsites'
Steven Murawski
Co-Host - Mind of Root (www.mindofroot.com)
Host - PowerShell Basics (powershell-basics.com)
bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
05 Feb 2008 03:04 PM  
Another option is to use -match (regex operator)

{ $_ -match "teamsites"}

or another way to use select-string
PS> Get-Content $file | Select-String "teamsites"
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer