MicrosoftDocs / PowerShell-Docs

The official PowerShell documentation sources
https://learn.microsoft.com/powershell
Creative Commons Attribution 4.0 International
1.93k stars 1.55k forks source link

syntax error in example 16 for get-winevent doc, "<=" in filterxml #11176

Closed jszabo98 closed 3 weeks ago

jszabo98 commented 3 weeks ago

Type of issue

Code doesn't work

Feedback

$xmlQuery = @'
 <QueryList>
   <Query Id="0" Path="Windows PowerShell">
     <Select Path="System">*[System[(Level=3) and
         TimeCreated[timediff(@SystemTime) <= 86400000]]]</Select>
   </Query>
 </QueryList>
'@

Get-WinEvent -FilterXML $xmlQuery

Get-WinEvent : Cannot bind parameter 'FilterXml'. Cannot convert value "<QueryList>
  <Query Id="0" Path="Windows PowerShell">
    <Select Path="System">*[System[(Level=3) and
        TimeCreated[timediff(@SystemTime) <= 86400000]]]</Select>
  </Query>
</QueryList>" to type "System.Xml.XmlDocument". Error: "Name cannot begin with the '=' character, hexadecimal value 0x3D. Line 4, position 44."
At line:1 char:25
+ Get-WinEvent -FilterXML $xmlQuery
+                         ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-WinEvent], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetWinEventCommand

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-winevent?view=powershell-7.4

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.4/Microsoft.PowerShell.Diagnostics/Get-WinEvent.md

Author

@sdwheeler

Document Id

77c520e7-966b-6f91-9414-859d3c33a653

sdwheeler commented 3 weeks ago

Use &lt;= instead of <=. That is what is actually written in the markdown source for the article. There is a bug in our docs rendering system that is converting &lt;= when it shouldn't. I am working to get that fixed.