Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How to remove specific rows from csv files in powershell?

$
0
0

Hello,

The code below is removing second and last row from csv files. Do you have any suggestion how to improve this code so it will take less time to run? Now it takes almost 8 minutes to remove second and last row from 5000 files.

 

(gci *.csv )|ForEach{
    $Path = $_.FullName
    $content = gc $Path
    $content|select -first 1|Out-File $Path -force
    $content[2..($content.count-2)]|Out-File $Path -Append
}


Thank you.

Viewing all articles
Browse latest Browse all 6937

Trending Articles