I built an XML object of type System.Xml.XmlDocument.
$scheme.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False XmlDocument System.Xml.XmlNode
I use the method save() to save it to a file.
$scheme.save()
This saves the file in format UTF-8 with BOM. The BOM causes issues with other scripts down the line.
When we open the XML file in Notepad++ and save it as UTF-8 (without the BOM), other scripts down the line don't have a problem. So I've been asked to save the script without the BOM.
The MS documentation for the save method states:
The value of the encoding attribute is taken from the XmlDeclaration.Encoding property. If the XmlDocument does not have an XmlDeclaration, or if the XmlDeclaration does not have an encoding attribute, the saved document will not have one either.
The MS documentation on XmlDeclaration lists encoding properties of UTF-8, UTF-16 and others. It does not mention a BOM.
Does the XmlDeclaration have an encoding property that leaves out the BOM?
PS. This behavior is identical in Powershell 5 and Powershell 7.