【问题标题】:Get-EventLog -After queryGet-EventLog - 查询后
【发布时间】:2015-04-01 19:28:58
【问题描述】:

当我在 powershell 上一一运行以下命令时,我得到了预期的结果。但是,当我将它作为 PS 脚本运行时,我没有得到任何输出。

$StartDate = Get-Date

Write-EventLog -LogName Application -Source "MsiInstaller" -EventId 11707 -Message "Product: Installation operation completed successfully."

Get-EventLog Application -After "$StartDate" -Source "MsiInstaller"

缺少什么?

【问题讨论】:

  • 是否允许powershell执行脚本? (试试get-executionPolicy

标签: powershell


【解决方案1】:

这是事件日志的准确性,当您在脚本中运行它时,这一切都发生在同一秒内。

试试这个:

$StartDate = Get-Date

Write-EventLog -LogName Application -Source "MsiInstaller" -EventId 11707 -Message "Product: Installation operation completed successfully."

start-sleep(1)

Get-EventLog Application -After "$StartDate" -Source "MsiInstaller"

【讨论】:

  • 我不完全确定您实际上要做什么。这似乎只是问题的一部分。
  • 我正在捕获安装内部产品之前的日期时间。安装相同产品后;我想找出在时间间隔之间生成的 MisInstaller 事件。同样,我正在模拟代码。在同一代码中,如果我使用 -newest 2 (例如) post sleep 命令;有用。但是对于 -After switch 它没有。您是否尝试过将其作为 PS 脚本运行。因为单行有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
相关资源
最近更新 更多