我想運行PowerShell腳本並嘗試按消息過濾。PowerShell錯誤使用GetEventLog CmdLet
param($server,$message)
Try
{
Invoke-Command -computername $server {Get-Eventlog -logname application -source "source" -message $message | Format-List}
}
Catch [Exception]
{
Write-Host $_.Exception.ToString()
}
試圖用下面的參數
運行腳本GetEventLog.ps1 「服務器名稱」, 「TEXT_TO_FIND」
無法驗證的參數 '消息' 的說法。參數爲空或空。提供一個非空的參數或 爲空,然後再次嘗試該命令。 + CategoryInfo:InvalidData:(:) [獲取,事件日誌],ParameterBindingValidationException + FullyQualifiedErrorId:ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetEventLogCommand
出於某種原因,處理$服務器參數正常,但如果抱怨有關$消息變量。
任何線索?
Get-EventLog太慢了!!我結束使用這個.. Get-WinEvent -computername $ server -FilterHashTable @ {LogName ='application'; providername = $ provider} | Where-Object {$ _。Message -match $ message -And $ _。TimeCreated -ge $ after -And $ _。TimeCreated -le $ before} – Maverick 2012-04-18 19:48:12