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]


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.



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

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