Skip to content

Instantly share code, notes, and snippets.

@J0rtIT
Forked from vors/xmlToString.ps1
Created April 16, 2020 05:27
Show Gist options
  • Save J0rtIT/42850fc9d32b72f1ff6dc44a5e81589d to your computer and use it in GitHub Desktop.
Save J0rtIT/42850fc9d32b72f1ff6dc44a5e81589d to your computer and use it in GitHub Desktop.
PowerShell function to convert any [xml] element to string
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