Get-EventLog-查询后

时间:2015-04-01 10:20:55

标签: powershell

当我逐一在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"

缺少什么?

1 个答案:

答案 0 :(得分:0)

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

试试这个:

$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"