1
我編寫了一個小腳本,用於在過去10天內從應用程序中檢索事件日誌,但收到錯誤消息。任何想法爲什麼錯誤出現?Powershell:過濾事件日誌
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert value "False" to type "System.Management.Automation.ScriptBlock". Error: "Invalid cast from 'System.Boolean' to 'System.Management.Automation.ScriptBlock'."
#Sets the application log to query
$Log ="Application"
$FilterHashTable = @{LogName=$Log}
#stores the computer name
$ComputerName = $env:COMPUTERNAME
#sets the date 10 days ago
$DeleteDate = Get-Date
$DeleteDate = $DeleteDate.AddDays(-10)
Write-Verbose $DeleteDate
#retrieve WMIevent and logs the information
$Winevent = Get-WinEvent -ComputerName $ComputerName -FilterHashTable $FilterHashTable -ErrorAction SilentlyContinue
# Filter on time
$Winevent | where-object ($_.timecreated -gt $DeleteDate)
謝謝,不管我看多少我看不到問題的地方對象。謝謝。即使$ deletedate是8/04/12,仍然存在一個問題,它仍然顯示來自26/01/2012的對象 – resolver101 2012-04-18 16:25:24
@ resolver101它可能是一個區域設置。你在Windows中設置了哪些區域? – JNK 2012-04-18 16:41:29
英國英國。 – resolver101 2012-04-19 10:14:10