## powershell -NoProfile -ExecutionPolicy Bypass -File xmlformatter.ps1 XMLファイル名 param( [Parameter(Mandatory = $true)] [string] $InputPath ) if (Test-Path $InputPath) { $base = [System.IO.Path]::GetFileNameWithoutExtension($InputPath) $OutputPath = ([System.IO.Path]::GetFullPath($base) + ".new.xml") } else { Write-Host "ファイルなし" exit } ## 整形用にインデントを指示 $settings = New-Object System.Xml.XmlWriterSettings $settings.Indent = $true ## XML読み込み $xmldoc = New-Object System.Xml.XmlDocument $xmldoc.Load($InputPath) ## XML整形結果書き出し $writer = [System.Xml.XmlWriter]::Create($OutputPath, $settings) $xmldoc.Save($writer) $writer.Close()