我们有一台服务器运行我们的备份软件,而且软件有自己的事件日志。 我可以用这个命令检索最近的事件日志条目:
Get-EventLog EventLogName -ComputerName server.example.com -newest 1
这给了我这样的结果:
Index Time EntryType Source InstanceID Message ----- ---- --------- ------ ---------- ------- 64292 Aug 13 15:51 Information BackupSoftware 29593 Transfer of 1096 KB...
如果最近事件的时间戳超过一个小时,我想要做的就是触发一个动作(比如说启动第二个脚本)。
任何帮助,将不胜感激。
$Event = Get-EventLog Application | ? { $_.Source -EQ 'BackupSoftware' } | Sort Time | Select -Last 1 If($Event.Time -LT (Get-Date).AddHours(-1)) { Do-Stuff }
这将在应用程序日志中find“BackupSoftware”的来源中的最新事件。
$Event = Get-EventLog BackupSoftware | Sort Time | Select -Last 1 If($Event.Time -LT (Get-Date).AddHours(-1)) { Do-Stuff }
这将在名为BackupSoftware的自定义日志中查找最近发生的事件,而不pipe源或EventId。
在这两种情况下,如果事件超过一个小时,脚本将会Do-Stuff事情”( Do-Stuff 。