I’m playing with the cmdlet Get-WinEvent I see something happening that I don’t understand.
This is what I’m doing.
For example, the following two commands give me back a result.
$FilterHashTable = @{logname='System','Application'; StartTime=(Get-Date).Date.AddDays(-1); Level=2,3}; Get-WinEvent -FilterHashtable $FilterHashTable -ComputerName localhost | Select-Object TimeCreated, LevelDisplayName, Message, logname;
So that showes me that it is allowed to work with more than one logname and with more than one loglevel.
When I examine $FilterHashTable, I see that it’s typename is System.Collections.Hashtable. With for example $FilterHashTable.logname[0] being ‘System’ and $FilterHashTable.logname[1] being ‘Application’. That looks ok to me.
When I do the following, I get the error message: "There is not an event log on the localhost computer that matches “System Application”.
$FilterHashTable = @{logname='System','Application'; StartTime=(Get-Date).Date.AddDays(-1); Level=2,3}; Invoke-Command -ScriptBlock {param ($FilterHashTable) Get-WinEvent -FilterHashtable $FilterHashTable} -ArgumentList $FilterHashTable -ComputerName localhost
As a final test I do this, only 1 logname and only 1 loglevel.
$FilterHashTable = @{logname='System'; StartTime=(Get-Date).Date.AddDays(-1); Level=2}; Invoke-Command -ScriptBlock {param ($FilterHashTable) Get-WinEvent -FilterHashtable $FilterHashTable} -ArgumentList $FilterHashTable -ComputerName localhost
And this one works, just like the first one.
Does anyone know why the second construct won’t work? Am I doing something wrong in the second construct? Or is it just impossible to do this in one command?
My aim is to run this to get today’s or yesterday’s errors and warnings from multiple servers, preferably presenting the message, logname and computername in one flow of objects. And the second construct looks good, so I’m curious whether there is a way to get it to work.
By the way, I’ve tried this with Powershell v4 against Windows 2012R2 and against Windows 8.1, but also with Powershell v3 against Windows 7 and Windows 2008R2. Both gave the same error on the second construct.