Adam McGurk
Adam McGurk

Reputation: 476

Select-Object omitting output from Select-String powershell

I wrote a Powershell script that looks for a string (such as ERROR) in log files and grabs those lines and outputs those lines to a file, for simpler reading and such (the industry I'm in has VERY large log files), but I'm having an issue. Before, when the (relevant) part of the code looked like this:

Select-String -Path "$file" -Pattern "$string" -CaseSensitive | Out-File -filepath $filepath

It would output the file path, the line number, and then the actual line, making for a very cluttered file. Well I only needed the line and the line number, so I did this:

Select-String -Path "$file" -Pattern "$string" -CaseSensitive | Select-Object -Property LineNumber,Line | Out-File -filepath $filepath

Which would return lines looking like this:

978 2017-07-10 10:46:11,288 ERROR [Music...

That is the line number then the line, with the line only totaling 35 characters.
Before I piped Select-String to Select-Object, the script would output the whole line, but now with Select-Object it omits some output. I tried adding -verbose parameters to both Select-String and Select-Object, but that did nothing.

Upvotes: 1

Views: 1336

Answers (1)

ClumsyPuffin
ClumsyPuffin

Reputation: 4059

Can you try this :

Select-String -Path "test.xml" -Pattern "ERROR" -CaseSensitive | ft -Property LineNumber,Line -Wrap  | Out-File -FilePath c:\out.txt

The reason for your problem is screen buffer length(increasing powershell screen buffer width) ,you can change it as well but the above snippet is simpler and effective

Upvotes: 3

Related Questions