Having some trouble searching a log file. I have a basic script that searches for specific text in a log file. The problem is, I am trying to use variables that can be adjusted by the user at the command line but I cannot get them to be recognized. The script should output the results back to the screen.
param (
[string]$file ,
[string]$Ip ,
[string]$port
)
Get-Content -Path C:\$file | Where-Object {$_ -like $Ip -and $_ -like $port}
Example of command line to execute script:
PS C:\> .\LogSearch.ps1 logfile04.txt 192.168.1.7 21
In this case, logfile04.txt
is the file, the port is 21
and the IP address is 192.168.1.7
At this point of running the script, I am returned with nothing, but there is that line within the file.
4|Oct 19 2015|18:28:39|106023|75.76.77.80|50077|192.168.1.7|21|Deny tcp src