windows - 为什么有时 powershell cmdlet“select-string”不返回任何值?
问题描述
此命令有效,logfolder 包含多个日志文件,select-string 将搜索每个文件并查找 -pattern 'update'
get-childitem -recurse C:\logfolder -file | select-string -pattern "update"
但是另一条线不起作用,它不会返回任何结果
get-eventlog -logname system -entrytype error | select-string -pattern "terminated"
我 100% 肯定有一个字符串“终止”的事件,也许我在这里遗漏了一些概念。
解决方案
select-string 将输入对象转换为字符串。不幸的是,使用 get-eventlog 这不是很有帮助。顺便说一句,get-eventlog 已被 get-winevent 取代。
get-eventlog -logname system -entrytype error | select -first 1
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
63255 Aug 31 07:44 Error Microsoft-Windows... 1129 The processing of Group Policy failed because o...
get-eventlog -logname system -entrytype error | select -first 1 | % { "$_" }
System.Diagnostics.EventLogEntry
get-eventlog -logname system -entrytype error | select -first 1 | select-string log
System.Diagnostics.EventLogEntry
get-eventlog -logname system -entrytype error | select -first 1 |
where message -match processing
Index Time EntryType Source InstanceID Message
----- ---- --------- ------ ---------- -------
63255 Aug 31 07:44 Error Microsoft-Windows... 1129 The processing of Group Policy failed because of lack of network connectivity to a domain controller. This may be a transient cond...
get-winevent @{logname='system';level=2} -maxevents 1 |
? message -match processing | ft -GroupBy logname
ProviderName: System
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
8/31/2021 7:44:27 AM 1129 Error The processing of Group Policy failed because of lack of network connectivity to a domain controller. This may be a transient condition. A success...
推荐阅读
- excel - 通过单元格值引用工作表 - Excel
- c++ - 引发编译时错误
- node.js - 使用 node.js 和 react.js 客户端启动一个 firebase 功能项目
- reactjs - 向 Graphcool 电子邮件密码模板突变添加字段
- bootstrap-4 - 重新排序 Bootstrap 4 网格
- javascript - 绘图图表不适用于 JSON 数据 PHP
- shell - 如何将 grep 的每个输出通过管道传输到另一个命令?
- react-native - 卸载 expo sdk 并改为设置 firebase
- mixins - pugjs - 单选按钮检查属性作为变量
- html - Outlook 2010 电子邮件背景颜色 html/css 属性不起作用