I need to delete the empty rows at end of the CSV file using Powershell. I tried the below code This code only working to remove the line 7 and 8 in the below sample file image. But I need to delete rows 3,4,5,6,7 and 8. Only row 2 has data. Any suggestion would be appreciated. thank you.
$content = [System.IO.File]::ReadAllText("PPC.csv")
$content = $content.Trim()
[System.IO.File]::WriteAllText("PPC_1.csv", $content)