Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Comparison Operators Question

$
0
0

Question on searching.   both scripts below work.  I have a .TXT file that contains all 30 NFL teams in alphibetical order.  If I run the first script and I
search for -like '*New"' it will return

The team you are seeking:   New England Patriots
The team you are seeking:   New Orleans Saints
The team you are seeking:   New York Giants
The team you are seeking:   New York Jets


# Script 1
$nfl = Get-Content "c:\temp\nfl.txt"
foreach ($team in $nfl) { IF ($team -like '*New*') { Write-Host "The team you are seeking:  " $team}}


but with script 2 below using -like and -contains don't work.  I had to use -match.  Why?  How is using READ-HOST different than Script 1 ?

# Script 2
$Find = Read-Host "Enter part of the team name"
$nfl = Get-Content "c:\temp\nfl.txt"
foreach ($team in $nfl) { IF ($team -match $Find) { Write-Host "The team you are seeking:  " $team}}


Viewing all articles
Browse latest Browse all 6937

Trending Articles