Last active
January 9, 2021 04:58
-
-
Save PrateekKumarSingh/96032bd63edb3100c2dda5d64847a48e to your computer and use it in GitHub Desktop.
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 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