PowerShell FINDSTR eqivalent?

后端 未结 8 944
栀梦
栀梦 2021-02-02 09:28

What\'s the DOS FINDSTR equivalent for PowerShell? I need to search a bunch of log files for \"ERROR\".

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-02 09:54

    if ($entry.EntryType -eq "Error")
    

    Being Object Oriented, you want to test the property in question with one of the standard comparison operators you can find here.

    I have a PS script watching logs remotely for me right now - some simple modification should make it work for you.

    edit: I suppose I should also add that is a cmdlet built for this already if you don't want to unroll the way I did. Check out:

    man Get-EventLog
    Get-EventLog -newest 5 -logname System -EntryType Error
    

提交回复
热议问题