Retrieving and Formatting XML as a table

Welcome Forums General PowerShell Q&A Retrieving and Formatting XML as a table

This topic contains 2 replies, has 2 voices, and was last updated by

3 months ago.

  • Author
  • #134445

    Points: 89
    Rank: Member

    I have some CloudWatch logs which are extracts from the Windows System Event Log. So the extraction is fairly straight forward.

    $results = (Get-CWLLogEvents @parameters).Events

    Output below

    Where I am having a problem is extracting and formatting the XML contained in the Message property. I've not done much work with XML and I'm having a mental block with this one. Any guidance would be appreciated.



  • #134493

    Points: 639
    Helping Hand
    Rank: Major Contributor

    If you define or cast XML, you can simply use dot notation:

    • #134517

      Points: 89
      Rank: Member

      Thanks, that's a nice simple solution. Hit a problem though, when I cast the message to XML, I get the following error, I'll need to investigate.

      Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "'.', hexadecimal value 0x00, is an invalid character. Line 1,
      position 1095."
      At line:1 char:1
      + [xml]$log = $results.message
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException
      + FullyQualifiedErrorId : RuntimeException

The topic ‘Retrieving and Formatting XML as a table’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort