Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a directory that inadvertently had about 1.4 million files generated into it. I want to list just the first, say, 100 items, but without the underlying process trying to read the entire directory contents internally, which causes a very long wait which, at this stage, has been processing for nearly an hour.

How do I do this with Powershell?

share|improve this question
this question seems to belong to stackoverflow.Maybe last post in… would be helpful ? – Sergei Dec 28 '11 at 13:09
Is powershell operation not a system administration issue? – Nathan Ridley Dec 28 '11 at 14:11
It is used by system administrators, however your question sounds like a coding task.Nothing wrong to have it here, but I think you are more likely to have question answered among coders. – Sergei Dec 28 '11 at 14:15
Fair enough. It's not a coding task, I just want to delete files. I'm using FastCopy now, which seems to be doing the trick. – Nathan Ridley Dec 28 '11 at 14:30
@Sergei : The last post in that stackoverflow thread implies that you take ALL the content and pipe it through a selection filter. That way, Nathan would have to wait for the 1.4 million file handles to get loaded into memory, just to discard 1.3999 million of them :-) – Mathias R. Jessen Dec 28 '11 at 20:35
up vote 3 down vote accepted

Want the first hundred items in a directory?


Only want files?

@(dir -File)[1..100]

Want to skip the first 40 directories and get the next 200?

@(dir -Directory)[41..240]
share|improve this answer
Great answer, thanks! – Nathan Ridley Dec 28 '11 at 21:27
This will still read through all files and then return a list of the preferred length. – tplive Jan 19 '15 at 13:46
It most certainly will, it just won't print them all to the screen – Mathias R. Jessen Jan 19 '15 at 14:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.