首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >get-winevent:使用属性

get-winevent:使用属性
EN

Stack Overflow用户
提问于 2018-01-29 15:11:20
回答 1查看 3.5K关注 0票数 0

我试着学习powershell来自动完成一些日常任务。

我试着从get-winevent函数中找出所有的字段名,以便了解当我想要过滤很多带有几种条件的事件i的结果时,我需要做什么。

在这个简单的例子中,我想要所有的事件4625和4624中的事件,但前提是logontype是2。结果应该只包括给定的字段(现在是所有字段,后面是选定的字段和一个自定义字段)。另外,我想用“本地”或“远程”和网络数据(IP、用户名、主机名)标记特定列中的本地登录和远程登录。

代码语言:javascript
复制
Get-winevent -FilterHashtable @{Path="c:\temp\test.evtx";} |
Where-Object {$_.Id -eq 4624 -and $_.properties[8].value -in 2} 
-or
{$_.Id -eq 4625}| export-csv ($EventlogTempFolder+$_.basename + ".csv") -encoding UTF8 -NoTypeInformation -force

怎样才能得到所有字段的列表?从ID到消息字段中的所有属性字段?

顺便说一句:这段代码没有像预期的那样工作。对此很抱歉。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-29 15:44:45

你的代码

代码语言:javascript
复制
Where-Object {$_.Id -eq 4624 -and $_.properties[8].value -in 2} 
-or
{$_.Id -eq 4625}

来自Get-Help Where-Object

代码语言:javascript
复制
Where-Object [-FilterScript] <ScriptBlock> [-InputObject <PSObject>] [<CommonParameters>]

...

Starting in Windows PowerShell 3.0, there are two different ways to construct a Where-Object 
command. Script block . You can use a script block to specify the property name, a comparison 
operator, and a property value. Where-Object returns all objects for which the script block 
statement is true.

For example, the following command gets processes in the Normal priority class, that is, 
processes where the value of the PriorityClass property equals Normal.

`Get-Process | Where-Object {$_.PriorityClass -eq "Normal"}`

问题

Where-Object CmdLet只接受一个脚本块( {}大括号中的位)

修复

代码语言:javascript
复制
Where-Object {
    ($_.Id -eq 4624 -and $_.properties[8].value -in 2)
    -or
    $_.Id -eq 4625
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48504367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档