Navigate to the directory where you have the files.
- Select only the first five files and directories from the returned list, using the First parameter.
PS> Get-ChildItem . | Select-Object -First 5
- Let us say you would like to pick the last five elements.
PS> Get-ChildItem . | Select-Object -Last 5
- To skip the first three objects:
PS> Get-ChildItem . | Select-Object -Skip 3
- If you would like to skip the last two objects:
PS> Get-ChildItem . | Select-Object -SkipLast 2
- To pick the fourth element from the output:
PS> Get-ChildItem . | Select-Object -Index 3
- Now, combine it with what we learnt in the previous recipe. Pick only the file names and the last modified time of the first four elements.
PS> Get-ChildItem . | select -Property Name, LastWriteTime -First 4