Powershell 获取事件日志-查询后

Powershell 获取事件日志-查询后,powershell,Powershell,当我在powershell上逐个运行下面的命令时,就会得到预期的结果。但是,当我将其作为PS脚本运行时,我没有得到任何输出 $StartDate = Get-Date Write-EventLog -LogName Application -Source "MsiInstaller" -EventId 11707 -Message "Product: Installation operation completed successfully." Get-EventLog Applicatio

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

缺少什么?

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

试试这个:

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

是否允许powershell执行脚本?试试执行政策我不完全确定你到底想做什么。这似乎只是问题的一部分。我正在捕获安装内部产品之前的日期时间。相同产品安装后;我想找出在两个时间间隔之间生成的错误安装程序事件。同样,我也在模拟代码。在相同的代码中,如果我使用-2,例如post sleep命令;它起作用了。然而,在切换之后,它并没有这样做。您是否尝试将其作为PS脚本运行。因为各条线都能工作。