我们有一台运行我们备份软件的服务器,该软件有自己的事件日志.我可以使用此命令检索最新的事件日志条目:
- 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
- }
这将在应用程序日志中找到具有“BackupSoftware”源的最新事件.
- $Event = Get-EventLog BackupSoftware | Sort Time | Select -Last 1
- If($Event.Time -LT (Get-Date).AddHours(-1))
- {
- Do-Stuff
- }
这将在名为BackupSoftware的自定义日志中找到最新事件,无论源或EventId如何.
在这两种情况下,如果事件超过一个小时,脚本将为Do-Stuff.