title: Need to extract the XML data to CSV
body: <p>I need to read specific information from event log. in below script I cannot export the some value contains in XML View. In the XML view I Want Target username: BRSYSAD and Subjectusername : 900011-LT</p>
  <p>Script</p>
  <pre><code>$filter = &quot;*[System[EventID=4740 and Provider[@Name='Microsoft-Windows-Security-Auditing']]]&quot;
  $result = Get-WinEvent -LogName Security -FilterXPath $filter | ForEach-Object {
      # convert the event to XML and grab the Event node
      $eventXml = ([xml]$_.ToXml()).Event
      # output the properties you need
      [PSCustomObject]@{
          EventID       = $eventXml.System.EventID.'#text'
          TimeCreated   = $eventXml.System.TimeCreated.SystemTime -replace '\.\d+.*$'
          Computer      = $eventXml.System.Computer
          Data          = $eventXml.EventData.Data
      }
  }
  
  # output on screen
  $result | Format-Table -AutoSize
  
  # save as CSV file if you like
  $result | Export-Csv -Path 'C:\MyProgr_Events_302.csv' -NoTypeInformation
  </code></pre>
  <p><a href="https://i.stack.imgur.com/aT7pd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aT7pd.png" alt="Current Output" /></a></p>
  <p><a href="https://i.stack.imgur.com/9csfX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9csfX.png" alt="Event log XML View" /></a></p>