1

I am writing a script to connect to remote servers and get the log.

This is woking:

foreach ($serv in $server) {
    Invoke-Command {
        Get-WinEvent -FilterHashtable @{
            logname   = 'application';
            starttime = '18/08/2017 10:00:00'
        }
    } -Credential $cred -ComputerName $serv
}

But when I try to pass dynamic values like follows:

$application = "Application"

foreach ($serv in $server) {
    Invoke-Command {
        Get-WinEvent -FilterHashtable @{
            logname   = $application;
            starttime = '18/08/2017 10:00:00'
        }
    } -Credential $cred -ComputerName $serv
}

It shows an error:

A null value was encountered in the logname hash table key. Null values are not
permitted.
    + CategoryInfo          : InvalidArgument: (logname:String) [Get-WinEvent], Exception
    + FullyQualifiedErrorId : NullNotAllowedInHashtable,Microsoft.PowerShell.Commands.GetWinEventCommand
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
San
  • 226
  • 5
  • 14

0 Answers0