Search code examples
windowspowershellget-winevent

How to include ProviderName in the command that gets event logs in the past ten hours


$A = @{}
$A.Add("StartTime", ((Get-Date).AddHours(-10)))
$A.Add("EndTime", (Get-Date))
$A.Add("LogName", "System")
(Get-WinEvent -FilterHashtable $A|Select TimeCreated, ProviderName, Message|FL)

The above commands will get all "System" event logs in the past 10 hours. However, I want to get only the event logs of "Microsoft-Windows-WindowsUpdateClient" in the past 10 hours. I tried the following line, which caused an error.

$A.Add("LogName", "System" ; "ProviderName", "*UpdateClient")

How should I include "ProviderName" in the command?


Solution

  • You have to add another key and value using Add method

    $A.Add("ProviderName", "*UpdateClient")