Retrieving and Formatting XML as a table

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

[pre]$results = (Get-CWLLogEvents @parameters).Events[/pre]

[pre]$results.message[/pre]

Output below

https://github.com/Nick-Rimmer2016/Snippets/blob/master/xmloutput

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.

Thanks

 

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

https://gist.github.com/rasimmers/08450e7c5af6601d7471d5e5bb706378

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