I have a function I am using to create an XML file, but for some reason I am not able to figure out how to silently create it. No matter what I have tried, I get the below echoed to the screen:
MemberType : Method
OverloadDefinitions : {void Flush()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : void Flush()
Name : Flush
IsInstance : True
Outside of this, the script works fine. After some testing, I found that it is the Flush that is causing this output. Is the flush required? I have seen scripts that don't have the flush but for the most part, the majority of the samples I have seen use flush
Here is my script
$filePath = "c:\users\blah\Profile-Update.xml"
$givenName = "test"
$encoding = [System.Text.Encoding]::UTF8
$XmlWriter = New-Object System.XMl.XmlTextWriter($filePath,$encoding)
$xmlWriter.Formatting = "Indented"
$xmlWriter.WriteStartDocument()
$xmlWriter.WriteStartElement("MappableItem")
$XmlWriter.WriteStartElement("FIRSTNAME")
$XmlWriter.WriteCdata($givenName)
$xmlWriter.WriteEndElement()
$xmlWriter.WriteEndElement() # <-- Closing RootElement
$xmlWriter.WriteEndDocument()
$xmlWriter.Finalize
$xmlWriter.Flush
$xmlWriter.Close()