Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I view a log file from powershell console ? (i.e. powershell equivalent of 'less')

What is the powershell equivalent of 'less'?

I see 'more', but it lacks some of the features I rely on (e.g. searching through the file)

I seek a pager (equivalent of 'less') which allows searching (match or ignore case), multiple files at once, etc.

Some of our servers run windows 2008 and I lack admin privileges to install cygwin

I had heard windows 2008, MSFT got their act together and provided some easy-for-admins tools.

Update:

I should give some context:

  • I know little about power shell
  • New servers have 2008 on them
  • While I affection for many tools of yore, the dos prompt is not one of them
  • I was hoping that Powershell had the equivalent of grep,ls,less, xargs, et
  • I understood that powershell gave us those tools
  • I fired off my question quickly.

thanks

like image 322
user331465 Avatar asked May 20 '11 14:05

user331465


People also ask

How do I view a PowerShell log file?

PowerShell logs can be viewed using the Windows Event Viewer. The event log is located in the Application and Services Logs group and is named PowerShellCore .

What is less command in PowerShell?

The Powershell Community Extensions have a handy function named 'less' that provides a more complete Unix-style feature set, using a ported copy of less.exe to actually handle the paging. You can install it by starting an admin shell and running: Find-Package pscx | Install-Package -Force.

How do I view Windows event logs in PowerShell?

Viewing the Windows PowerShell Event Log To examine the events and their properties, use the Sort-Object cmdlet, the Group-Object cmdlet, and the cmdlets that contain the Format verb (the Format cmdlets). For more information, type "Get-Help Get-EventLog" and "Get-Help Get-WmiObject".

Which command can help in viewing the file data in PowerShell?

The Get-Content cmdlet uses the Path parameter to specify the LineNumbers. txt file and displays the content in the PowerShell console.


1 Answers

It reads like you know you can do this:

gc logfile.log | more

(GC is an alias for Get-Content).

You may be able to do the filtering etc.. with this more information can be found by running these commands:

Get-Help Get-Content Get-Help

Get-Content -Examples

(Get-Help gc would work fine as well).

And the bits you may be interested in are limit\filter etc...

Get-Help gc -Parameter * | more

like image 181
Matt Avatar answered Sep 28 '22 06:09

Matt