powershell - 获取 WinEvent powershell 。-包含与-匹配
问题描述
好吧,我正在处理安全事件日志,所以当我使用它-match
时where
,我等待结果,但我不明白如果我更换-match by -contains
,我没有结果。
使用此代码:
$ip='52.109.12.19'
$id = 5157
Get-WinEvent -FilterHashtable @{ LogName='security'; id=$id} |
Where {$_.Message -match $ip} |
select -Property id, message
结果是:
Id Message
-- -------
5157 La plateforme WPF (Windows Filtering Platform) a bloqué une connexion....
5157 La plateforme WPF (Windows Filtering Platform) a bloqué une connexion....
5157 La plateforme WPF (Windows Filtering Platform) a bloqué une connexion....
5157 La plateforme WPF (Windows Filtering Platform) a bloqué une connexion....
5157 La plateforme WPF (Windows Filtering Platform) a bloqué une connexion....
5157 La plateforme WPF (Windows Filtering Platform) a bloqué une connexion....
5157 La plateforme WPF (Windows Filtering Platform) a bloqué une connexion....
5157 La plateforme WPF (Windows Filtering Platform) a bloqué une connexion....
使用此代码:
$ip='52.109.12.19'
$id = 5157
Get-WinEvent -FilterHashtable @{ LogName='security'; id=$id} |
Where {$_.Message -contains $ip} |
select -Property id, message
没有结果
我想了解为什么我没有相同的结果.....
谢谢你的帮助
解决方案
Powershell-contains
的工作方式类似于 JavaScript 的Array#includes
.
它不会告诉您字符串是否包含某个子字符串。它只告诉您数组是否包含某个项目。
"abc" -contains "a"
是。$false.
"a","b","c" -contains "a"
_$true
如果您想拥有子字符串级别的“包含”,请使用运算符或字符串上可用-match
的 .NET方法。.Contains()
Get-WinEvent -FilterHashtable @{ LogName='security'; id=$id} |
Where {$_.Message.Contains($ip)} |
select -Property id, message
推荐阅读
- reactjs - Redux 用相同的动作连接多个组件
- excel - 我正在尝试选择所有具有多于一行的数字的行
- node.js - 如何通过cheerio获取图片网址?
- javascript - 每次以下代码中的“案例”更改时,如何刷新以下滑块的数组?
- c - C扫描用户输入(char),将其存储在变量中并与字符串进行比较
- c# - 如何使用 Visual Studio 代码将实体框架核心安装到 asp.net core 3 项目
- ecmascript-6 - 为什么使用 let 导致代码块中未定义?
- powershell - 如何将 powershell UTC 日期时间对象转换为 EST
- java - Java和hibernate一应用分离数据库
- c++ - 尽管我检查了空堆栈,但 C++ STL 堆栈弹出操作给出了段错误