【发布时间】:2012-04-26 04:40:55
【问题描述】:
我正在尝试运行 PowerShell 脚本并尝试按消息过滤。
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 "SERVERNAME" "TEXT_TO_FIND"
无法验证参数“消息”的参数。参数为 null 或空。提供一个不为空的参数或 清空,然后再次尝试该命令。 + CategoryInfo : InvalidData: (:) [Get-EventLog], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetEventLogCommand
由于某种原因,它可以很好地处理 $server 参数,但如果抱怨 $message 变量。
我该如何解决这个问题?
【问题讨论】:
-
Get-EventLog 太慢了!!我结束了使用这个.. Get-WinEvent -computername $server -FilterHashTable @{LogName='application';providername=$provider} | Where-Object {$_.Message -match $message -And $_.TimeCreated -ge $after -And $_.TimeCreated -le $before}
标签: powershell cmdlet