我试着学习powershell来自动完成一些日常任务。
我试着从get-winevent函数中找出所有的字段名,以便了解当我想要过滤很多带有几种条件的事件i的结果时,我需要做什么。
在这个简单的例子中,我想要所有的事件4625和4624中的事件,但前提是logontype是2。结果应该只包括给定的字段(现在是所有字段,后面是选定的字段和一个自定义字段)。另外,我想用“本地”或“远程”和网络数据(IP、用户名、主机名)标记特定列中的本地登录和远程登录。
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到消息字段中的所有属性字段?
顺便说一句:这段代码没有像预期的那样工作。对此很抱歉。
发布于 2018-01-29 15:44:45
你的代码
Where-Object {$_.Id -eq 4624 -and $_.properties[8].value -in 2}
-or
{$_.Id -eq 4625}来自Get-Help Where-Object
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只接受一个脚本块( {}大括号中的位)
修复
Where-Object {
($_.Id -eq 4624 -and $_.properties[8].value -in 2)
-or
$_.Id -eq 4625
}https://stackoverflow.com/questions/48504367
复制相似问题