Functions/XML/Out-Xml.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function Out-Xml {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [ValidateNotNullOrEmpty()]
        [xml]
        $InputObject
    )

    process {
        $StringWriter = New-Object System.IO.StringWriter
        $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter
        $XmlWriter.Formatting = "indented"

        $InputObject.WriteTo($XmlWriter)

        $XmlWriter.Flush()
        $StringWriter.Flush()

        $StringWriter.ToString().Replace(' xmlns=""', '')
    }
}