Skip to content

Commit 3aca0a5

Browse files
sdwheelerDCtheGeek
authored andcommitted
Fixes #4689 - search for keyword in eventdata (#4791)
1 parent 25d7284 commit 3aca0a5

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

reference/docs-conceptual/samples/Creating-Get-WinEvent-queries-with-FilterHashtable.md

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
ms.date: 03/18/2019
2+
ms.date: 09/13/2019
33
title: Creating Get-WinEvent queries with FilterHashtable
44
---
55

@@ -18,9 +18,11 @@ When you work with large event logs, it's not efficient to send objects down the
1818
log data. For example, the following commands are inefficient to filter the
1919
**Microsoft-Windows-Defrag** logs:
2020

21-
`Get-EventLog -LogName Application | Where-Object Source -Match defrag`
21+
```powershell
22+
Get-EventLog -LogName Application | Where-Object Source -Match defrag
2223
23-
`Get-WinEvent -LogName Application | Where-Object { $_.ProviderName -Match 'defrag' }`
24+
Get-WinEvent -LogName Application | Where-Object { $_.ProviderName -Match 'defrag' }
25+
```
2426

2527
The following command uses a hash table that improves the performance:
2628

@@ -44,7 +46,8 @@ For more information, see the
4446

4547
To build efficient queries, use the `Get-WinEvent` cmdlet with the **FilterHashtable** parameter.
4648
**FilterHashtable** accepts a hash table as a filter to get specific information from Windows event
47-
logs. A hash table uses **key/value** pairs. For more information about hash tables, see [about_Hash_Tables](/powershell/module/microsoft.powershell.core/about/about_hash_tables).
49+
logs. A hash table uses **key/value** pairs. For more information about hash tables, see
50+
[about_Hash_Tables](/powershell/module/microsoft.powershell.core/about/about_hash_tables).
4851

4952
If the **key/value** pairs are on the same line, they must be separated by a semicolon. If each
5053
**key/value** pair is on a separate line, the semicolon isn't needed. For example, this article
@@ -60,19 +63,36 @@ documentation for the [Get-WinEvent](/powershell/module/microsoft.powershell.dia
6063
The following table displays the key names, data types, and whether wildcard characters are accepted
6164
for a data value.
6265

63-
| Key name | Value data type | Accepts wildcard characters? |
64-
|------------- | ------------------ | ---------------------------- |
65-
| LogName | `<String[]>` | Yes |
66-
| ProviderName | `<String[]>` | Yes |
67-
| Path | `<String[]>` | No |
68-
| Keywords | `<Long[]>` | No |
69-
| ID | `<Int32[]>` | No |
70-
| Level | `<Int32[]>` | No |
71-
| StartTime | `<DateTime>` | No |
72-
| EndTime | `<DateTime>` | No |
73-
| UserID | `<SID>` | No |
74-
| Data | `<String[]>` | No |
75-
| * | `<String[]>` | No |
66+
| Key name | Value data type | Accepts wildcard characters? |
67+
| -------------- | --------------- | ---------------------------- |
68+
| LogName | `<String[]>` | Yes |
69+
| ProviderName | `<String[]>` | Yes |
70+
| Path | `<String[]>` | No |
71+
| Keywords | `<Long[]>` | No |
72+
| ID | `<Int32[]>` | No |
73+
| Level | `<Int32[]>` | No |
74+
| StartTime | `<DateTime>` | No |
75+
| EndTime | `<DateTime>` | No |
76+
| UserID | `<SID>` | No |
77+
| Data | `<String[]>` | No |
78+
| \<named-data\> | `<String[]>` | No |
79+
80+
The \<named-data\> key represents a named event data field. For example, the Perflib event 1008
81+
can contain the following event data:
82+
83+
```xml
84+
<EventData>
85+
<Data Name="Service">BITS</Data>
86+
<Data Name="Library">C:\Windows\System32\bitsperf.dll</Data>
87+
<Data Name="Win32Error">2</Data>
88+
</EventData>
89+
```
90+
91+
You can query for these events using the following command:
92+
93+
```powershell
94+
Get-WinEvent -FilterHashtable @{LogName='Application'; 'Service'='Bits'}
95+
```
7696

7797
## Building a query with a hash table
7898

0 commit comments

Comments
 (0)