0

我正在寻找使用 Powershell 来监视特定事件 ID 的 2003 和 08 服务器列表的“安全”日志。到目前为止,我已经使用了这个

    $servers = gc c:\temp\servers.txt
foreach ($server in $servers)
{
     $Query = "SELECT * FROM __instanceCreationEvent WHERE TargetInstancISA 'Win32_NTLogEvent' AND TargetInstance.LogFile = 'Security' AND TargetInstance.EventCode = '529' "

    Register-WMIEvent -ComputerName $server -Query $Query -sourceIdentifier "$server" -Action

    {Write-Host "The following Event ID of 529 has been found in the Security log on $server}

    }

但是如何才能获得日志条目的时间戳,并且只有最新的时间戳(如果存在)?

4

3 回答 3

2

忘记 WMI。使用获取事件日志。

[string[]]$Servers = @("server1","server2")
Get-EventLog -LogName Security -ComputerName $Servers -Newest 1 -InstanceId 529 | select EventID,TimeGenerated,MachineName
于 2013-02-22T10:57:25.163 回答
0

把事情简单化:

$servers = gc c:\temp\servers.txt
foreach ($server in $servers)
{
    $events = Get-EventLog -ComputerName $server -LogName "Security" | Where-Object     {$_.EventID -eq "529"}
    if ($events -ne $null)
    {
        foreach ($event in $events)
        {
            $event.TimeGenerated
        }
    }
}
于 2013-02-22T10:56:02.743 回答
0

我前段时间写了这篇文章,就是为了这样一个场合:

http://gallery.technet.microsoft.com/scriptcenter/ed188912-1a20-4be9-ae4f-8ac46cf2aae4

于 2013-02-22T11:23:49.580 回答