Created
May 16, 2025 03:00
-
-
Save scriptingstudio/b303a58c54a91dfc35ecaa50930ba200 to your computer and use it in GitHub Desktop.
XML to string converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Convert-XmlToString { | |
| param ( | |
| [Parameter(Mandatory,ValueFromPipeline)] | |
| $xml | |
| ) | |
| begin { | |
| $sw = [System.IO.StringWriter]::new() | |
| $xmlSettings = [System.Xml.XmlWriterSettings]::new() | |
| $xmlSettings.ConformanceLevel = [System.Xml.ConformanceLevel]::Fragment | |
| $xmlSettings.Indent = $true | |
| $xw = [System.Xml.XmlWriter]::Create($sw, $xmlSettings) | |
| } | |
| process { | |
| $xml.WriteTo($xw) | |
| } | |
| end { | |
| $xw.Close() | |
| $sw.ToString() | |
| } | |
| } # END Convert-XmlToString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment