2

我正在尝试从 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

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

4

1 回答 1

1

我不确定您要检索哪些信息,但我很确定有更好的方法,然后使用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
于 2016-03-24T15:01:01.950 回答