How to get row 10 till 30 from a csv file

Clinton van Axel 126 Reputation points
2021-06-04T08:09:55.007+00:00

Is it possible to get with powershell row 10 to 30 from a csv file?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,628 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,781 Reputation points
    2021-06-04T14:31:58.58+00:00

    If your CSV has a header row, and you want to get the same result as if you'd done an Import-CSV (but only on the selected data rows), try this:

    $h = @((get-content C:\junk\fwd.csv | Select-Object -First 1))         # just the header row
    $h += (get-content C:\junk\fwd.csv | Select-Object -Skip 11 -First 20)  # now get data rows 10 - 30
    $c = $h | ConvertFrom-CSV                                               # convert array of strings to an array of PSCustomObjects
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Franky 106 Reputation points
    2021-06-04T10:40:59.9+00:00

    try

    get-content C:\temp\test.txt | select -skip 10 -First 20

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.