Powershell Prettify XML

Got some XML you need to prettify in powershell? No problem!

Example xml:

<first><second><third>hello world</third><second><first>

Load the XML and preview it in the console prettified:

PS> [xml]$xml = Get-Content C:\temp\input.xml
PS> $xml.Save([System.Console]::Out)

<first>
  <second>
    <third>hello world</third>
  </second>
</first>

Load a file, prettify it, and save it as another file:

PS> [xml]$xml = Get-Content C:\temp\input.xml
PS> $xml.Save(c:\temp\output.xml)

 

Further reading