Search pattern and grab the whole row to result

Dear expert

I need this code below to work as I wanted, now this code below grab network shares and a $pattern show name, line and write time. I want it to if you find the Pattern grab the whole row. I tried |Get-Content but it grabbed everything. I don't need to know the name and line and write time, so i can just remove $LWT = (Get-Item -Path $_.Name).LastWriteTime $_.Group | Select-Object Path, LineNumber, @{n='LastWriteTime'; e={$LWT}}

Help please. Thanks

$networksshare = "\\rvp01\logs", "\\rvp01\logs2","\\rvp02\logs","\\rvp02\logs2","\\srvp03\logs","\\srvp03\logs"
$Pattern = 'List6-75'

$results = Get-ChildItem -Path $networksshare -Recurse -File |
	Select-String -Pattern $Pattern |
	Group-Object Path |
	ForEach-Object {
		$LWT = (Get-Item -Path $_.Name).LastWriteTime
		$_.Group | Select-Object Path, LineNumber, @{n='LastWriteTime'; e={$LWT}}
	
}
$results | Out-File d:\test\result.txt

Open in new window

LVL 1
WeTiAsked:
Who is Participating?
 
footechCommented:
$networksshare = "\\rvp01\logs", "\\rvp01\logs2","\\rvp02\logs","\\rvp02\logs2","\\srvp03\logs","\\srvp03\logs"
$Pattern = 'List6-75'

Like this?
$results = Get-ChildItem -Path $networksshare -Recurse -File |
	Select-String -Pattern $Pattern |
	Group-Object Path |
	ForEach-Object {
		$_.Group | Select-Object Path, Line
	
}
$results | Out-File d:\test\result.txt

Open in new window


It's not clear if you still need to group results, or show the path, but I left those in for now.
1
 
WeTiAuthor Commented:
Hi, due to the line is too long the outfile show like this:  

Line
2018-01-19 Warning (Some text here and end with)...

It shortend the row with ...

I am looking it to get full row.
0
 
WeTiAuthor Commented:
Format-list did the trick
1
 
footechCommented:
You could also try the -Width parameter of Out-File.  Just set to something long enough for your contents.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.