diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/Get-WinEvent.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/Get-WinEvent.Tests.ps1 index 8841f7181a..77cfca7489 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/Get-WinEvent.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/Get-WinEvent.Tests.ps1 @@ -73,8 +73,39 @@ Describe 'Get-WinEvent' -Tags "CI" { $results = Get-WinEvent -logname $logname -filterXPath $xpathFilter -max 3 $results | should Not BeNullOrEmpty } + } - # Get-WinEvent works only on windows + Context "Get-WinEvent UserData Queries" { + It 'Get-WinEvent can retrieve events with UserData queries using FilterXml' { + # this relies on apriori knowledge about the log file + # the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue + $eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx") + $filter = "" + $results = Get-WinEvent -FilterXml $filter -ea silentlycontinue + @($results).Count | Should be 1 + $results.RecordId | should be 10 + } + <# + It 'Get-WinEvent can retrieve events with UserData queries using FilterHashtable' { + # this relies on apriori knowledge about the log file + # the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue + $eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx") + $filter = @{ path = "$eventLogFile"; Param2 = "Windows x64"} + $results = Get-WinEvent -filterHashtable $filter -ea silentlycontinue + @($results).Count | Should be 1 + $results.RecordId | should be 10 + } + #> + It 'Get-WinEvent can retrieve events with UserData queries using FilterXPath' { + # this relies on apriori knowledge about the log file + # the provided log file has been edited to remove MS PII, so we must use -ea silentlycontinue + $eventLogFile = [io.path]::Combine($PSScriptRoot, "assets", "Saved-Events.evtx") + $filter = "*/UserData/*/Param2='Windows x64'" + $results = Get-WinEvent -path $eventLogFile -filterXPath $filter -ea silentlycontinue + @($results).Count | Should be 1 + $results.RecordId | should be 10 + } + } # Get-WinEvent works only on windows It 'can query a System log' { Get-WinEvent -LogName System -MaxEvents 1 | Should Not BeNullOrEmpty } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/assets/Saved-Events.evtx b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/assets/Saved-Events.evtx new file mode 100644 index 0000000000..9427f037a0 Binary files /dev/null and b/test/powershell/Modules/Microsoft.PowerShell.Diagnostics/assets/Saved-Events.evtx differ