Powershell XML encoding

I have a script that executes a stored procedure on a SQL Server which returns XML. I then have a function to to format the XML in powershell so it is readable. When i open the XML in Chrome i get this error:

This page contains the following errors:

error on line 149 at column 27: Encoding error
Below is a rendering of the page up to the first error.

I think I may need to encode it in UTF8 but I am unsure where to do it in my code. Any help to rectify the error or how to do the encoding is appreciated.