This behavior is expected, Get-Content and Out-File should not be sharing the same pipeline if reading and writing to the same file. Either, surround Get-Content with brackets or store the content in a variable and then write the file.
$dest = "C:\Test"
Get-ChildItem $dest *.csv | ForEach-Object {
(Get-Content $_.FullName) | Where { $_.Replace(",","").trim() -ne "" } |
Out-File $_.FullName
}
# OR
$dest = "C:\Test"
Get-ChildItem $dest *.csv | ForEach-Object {
(Get-Content $_.FullName | Where { $_.Replace(",","").trim() -ne "" }) |
Out-File $_.FullName
}
# OR
$dest = "C:\Test"
Get-ChildItem $dest *.csv | ForEach-Object {
$content = Get-Content $_.FullName | Where { $_.Replace(",","").trim() -ne "" }
Out-File -InputObject $content -FilePath $_.FullName
}