gpt4 book ai didi

powershell - 从 powershell 中的 Get-Winevent 消息中选择特定的行/数据

转载 作者:行者123 更新时间:2023-12-02 23:58:35 27 4
gpt4 key购买 nike

我正在尝试从 get-winevent cmdlet 的消息输出中提取特定行,但未能找到执行此操作的方法(我可能搜索不正确,但仍在学习更高级的脚本方法)。我正在运行的是:

Get-WinEvent -ComputerName $DC -FilterHashtable @{Logname='Security';Keywords='9007199254740992';Data=$userid} -MaxEvents 1 | Select Message | Format-List

这将返回一条类似于此的消息(将一些信息更改为通用信息):

Message : The computer attempted to validate the credentials for an account.
Authentication Package: MICROSOFT_AUTHENTICATION_PACKAGE_V1_0
Logon Account: jdoe
Source Workstation: Generic-Computername
Error Code: 0x0

我正在尝试创建一种简单的方法来查找某人上次登录的计算机以便更快地进行故障排除,但我无法仅过滤掉源工作站行,我可能只是没有正确的语法来进行良好的搜索以找到我正在寻找的结果,但我已经搜索了大约一个星期,但没有找到任何接近我正在寻找的东西,任何帮助都会很棒!

最佳答案

我不确定你想要检索什么信息,但我很确定有比使用 Get-WinEvent 更好的方法获取该信息。但是,如果您只想获取 Source Workstation 的值,您可以使用正则表达式来实现:

$event = Get-WinEvent `
-ComputerName $DC `
-FilterHashtable @{Logname='Security';Keywords='9007199254740992';Data=$userid} `
-MaxEvents 1 `
| Select -expand Message

[regex]::Match($event, 'Source Workstation:\s*(.*)\s*').Groups[1].Value

关于powershell - 从 powershell 中的 Get-Winevent 消息中选择特定的行/数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36202648/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com