Skip to content

Instantly share code, notes, and snippets.

@PrateekKumarSingh
Last active January 9, 2021 04:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save PrateekKumarSingh/96032bd63edb3100c2dda5d64847a48e to your computer and use it in GitHub Desktop.
Save PrateekKumarSingh/96032bd63edb3100c2dda5d64847a48e to your computer and use it in GitHub Desktop.
Function Format-XMLIndent
{
[Cmdletbinding()]
[Alias("IndentXML")]
param
(
[xml]$Content,
[int]$Indent
)
# String Writer and XML Writer objects to write XML to string
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
# Default = None, change Formatting to Indented
$xmlWriter.Formatting = "indented"
# Gets or sets how many IndentChars to write for each level in
# the hierarchy when Formatting is set to Formatting.Indented
$xmlWriter.Indentation = $Indent
$Content.WriteContentTo($XmlWriter)
$XmlWriter.Flush();$StringWriter.Flush()
$StringWriter.ToString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment