Powershell – Concatenate files

Example: To concatenate all .txt files in directory C:\temp and store result in outfile.txt

$ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) }

if (Test-Path "C:\temp\outfile.txt") {
    Remove-Item "C:\temp\outfile.txt"
}

Get-ChildItem "C:\temp" -Filter *.txt|sort-object $ToNatural | `
Foreach-Object{
  Write-Host $_
  #Get-Content $_ >> C:\temp\outfile.txt
}