PowerShell Version 5 New Feature: SkipLast Parameter added to Select-Object

I’m picking up where I left off in my last blog article on the new features in the PowerShell version 5 preview. Today I be covering a new parameter, SkipLast that has been added to the Select-Object cmdlet.

I have a text file where I saved a list of the available packages in the default OneGet Chocolatey repository. There are a total of 1893 items in this file:


I’ll use the new SkipLast parameter to skip the last 1885 items:


This blog article has been written based on the preview version of PowerShell version 5 from the May 2014 release of the Windows Management Framework 5.0 preview so what you’ve seen here is subject to change in the final release version.

This blog article is one of many that I’ve written and will be writing about the new features in PowerShell version 5. You can find my other blog articles on PowerShell version 5 here.


1 Comment

  1. Peggy H.

    Hello Mike,

    Thank you for your post here on the SkipLast parameter that has been added to PS version 5.

    I have Version 5 installed and I have been trying to automate a process for work where I want to delete the last two rows in a CSV coming from our PRTG (VPN) server. The last two lines are summary information which do not pertain to the upload that is next in the automation process.

    I tested your script against my data file and it displays all the correct lines to the screen but now I just need to save the file without the last two lines.

    I have attempted this within a ForEach-Object loop but get an error: “The process cannot access the file because it is being used by another process”.

    Here is the line that errors out: “Get-Content $fileDestPath | Select-Object -SkipLast 2 | Set-Content $fileDestPath”

    I am coming up with nothing …

    Thanks again


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: