Skip to content

Instantly share code, notes, and snippets.

@scriptingstudio
Created May 16, 2025 03:00
Show Gist options
  • Select an option

  • Save scriptingstudio/b303a58c54a91dfc35ecaa50930ba200 to your computer and use it in GitHub Desktop.

Select an option

Save scriptingstudio/b303a58c54a91dfc35ecaa50930ba200 to your computer and use it in GitHub Desktop.
XML to string converter
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