Powershell没有';无法准确显示结果(ip地址)

Powershell没有';无法准确显示结果(ip地址),powershell,select-string,Powershell,Select String,我尝试只获取1.1.2.1,但它也显示了其他ip 我的测试代码是 $reader = @([System.IO.File]::ReadAllLines("c:\test2.log")) |select-string "1.1.2.1" $reader = [System.IO.File]::ReadAllLines("c:\test2.log") |select-string "1.1.2.1" $reader = get-content c:\test2.log |select-strin

我尝试只获取
1.1.2.1
,但它也显示了其他
ip

我的测试代码是

$reader = @([System.IO.File]::ReadAllLines("c:\test2.log")) |select-string "1.1.2.1"

$reader = [System.IO.File]::ReadAllLines("c:\test2.log") |select-string "1.1.2.1"

$reader = get-content c:\test2.log |select-string "1.1.2.1"

  • test2.log

    10.1.101.1  test101
    
    10.1.102.1  test102
    
    121.132.252.1   test104
    
    100.101.122.1   test105
    
    1.1.1.1 test1
    
    1.1.2.1 test2
    
  • 结果

    10.1.102.1    test102
    
    100.101.122.1    test105
    
    1.1.2.1    test2
    
我不知道为什么它显示我
test102、test105

请告诉我怎么解决这个问题

我在Powershell v2、v3中尝试了这个


对不起,我忘了解释原始代码的一部分


{$pinghostname=Get Content$HOSTS |选择字符串模式“$ip”|%{($|-split”
t
t”)[1]}

“1.1.2.1”应为$ip

这意味着我不能使用regexp

get-content test2.log | Select-String "1\.1\.2\.1"
工作也一样

$ip="1\.1\.2\.1"
get-content test2.log | Select-String $ip

{$pinghostname=Get Content$HOSTS | Select String-Pattern“$ip”|%{($.-split“tt”)[1]}“1.1.2.1”应该是$ip,这意味着我不能使用regexpit解决选择String-SimpleMatch选项