2015-04-01 55 views
0

當我在PowerShell上一個接一個地運行下面的命令時,我得到了預期的結果。但是,當我將它作爲PS腳本運行時,我沒有得到任何輸出。Get-EventLog - 查詢後

$StartDate = Get-Date 

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

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

缺少什麼?

+0

是PowerShell的允許執行腳本? (嘗試'get-executionPolicy') – 2015-04-01 11:27:51

回答

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" 
+0

我試過但沒有運氣。 – 2015-04-01 11:40:09

+0

我不完全確定你究竟在做什麼。這似乎只是問題的一部分。 – 2015-04-02 13:58:21

+0

我在安裝內部產品之前捕獲日期時間。安裝相同的產品後;我想找出時間間隔內生成的MisInstaller事件。對於我正在模擬代碼。在相同的代碼中,如果我使用-newest 2(例如)post sleep命令;有用。但是 - 後切換它沒有。你有沒有試過它作爲PS腳本運行?因爲個別線路起作用。 – 2015-04-03 05:43:17