I am trying to run a PowerShell script and try to filter by the message.
param($server, $message)
Try
{
Invoke-Command -computername $server {Get-Eventlog -logname application -source "source" -message $message | Format-List}
}
Catch [Exception]
{
Write-Host $_.Exception.ToString()
}
I am trying to run the script with the following parameters:
GetEventLog.ps1 "SERVERNAME" "TEXT_TO_FIND"
cannot validate an argument on parameter 'Message'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again. + CategoryInfo : InvalidData: (:) [Get-EventLog], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetEventLogCommand
For some reason it handles the $server parameter fine, but if complains about the $message variable.
How can I fix this?