Delete rows from a table or excel file

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Mike Catalano Mike Catalano 7 months, 4 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34733
    Profile photo of Mike Catalano
    Mike Catalano
    Participant

    I'm completely new to PS so pardon my lack of knowledge here. I am downloading a report from a web API via the invoke-restmethod and attempting to format the data into a csv file to distribute. I can display the data on the console with a format-table, however on the table and in the csv file there are 5 junk rows at the top of the table. I've seen examples of how to delete these after saving the excel file, then opening the file and modifying it, and saving it again. I find that rather inefficient and would like to know if there was a way to do this before exporting to csv. The junk rows appear below the header row.

    #34734
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    If it's always 5 rows, you can do something like this:

    $filePath = 'c:\path\to\your.csv'
    
    $data = Import-Csv -Path $filePath
    
    $data | Select-Object -Skip 5 | Export-Csv -Path $filePath -NoTypeInformation
    
    #34736
    Profile photo of Mike Catalano
    Mike Catalano
    Participant

    that works very nicely. thank you

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.