Select-String in Powershell only displaying part of the line from a text file, need it to display whole thing

12,157

You are seeing it like this because it's displaying the Line property using the default Format-Table view and shortening it to the width of the console.

Do this instead:

$lines = Select-String -Path $logDir -Pattern "SRVE0242I:" | Select-Object -ExpandProperty line

This returns the value of the Line property as a string to the $lines variable. You don't need to use Out-String.

Share:
12,157
user3431504
Author by

user3431504

Updated on June 05, 2022

Comments

  • user3431504
    user3431504 almost 2 years

    I am trying to write a simple PS script to check large .txt log files for a short string: "SRVE0242I:"

    $lines = Select-String -Path $logDir -Pattern "SRVE0242I:" | Select-Object line | Out-String
    

    On output though, it only displays the following:

    Line
    [28/06/17 13:48:27:839] 00000020 ServletWrappe I SRVE0242I: [User] [User] [com_xxxxxxx_...

    And not the full line. Is there a limit to how many characters this pulls? I can't find any info on any restrictions for the Select-String cmdlet. Is there a better way to do this so that I don't a) pull the heading "Line" in my list of lines (Don't really want to create table formatting for such a simple output) and b) get the whole line when I pull the info?