-
-
Save J0rtIT/42850fc9d32b72f1ff6dc44a5e81589d to your computer and use it in GitHub Desktop.
PowerShell function to convert any [xml] element to string
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-XmlElementToString | |
{ | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true)] | |
$xml | |
) | |
$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) | |
$xml.WriteTo($xw) | |
$xw.Close() | |
return $sw.ToString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment