Powershell fastest directory list

僤鯓⒐⒋嵵緔 提交于 2021-02-07 08:14:24

问题


Anyone know a fast way to do a recursive directory listing? I am trying to go through a SAN of about 10tb and "get-childitem -include" takes days to run... I know there will be no way to bring it down to minutes but perhaps some way to cut the time to a few hours would be great. I only need a list i can sort through don't need the file properties as I will be using this to find certain types of files on our SAN such as PST files.

If anyone could point me in the direction on how to use the compiled code from HERE I should be good too.


回答1:


If it's just one extension that you're after use the Filter parameter, it's much faster than -Include. I'd also suggest to use PowerShell 3 is you can (get-childitem has the new -file switch), as far as I remember listing UNC paths performance was enhanced in it (with underlying .net 4 support).

Another option would be to use the dir command from a cmd window, should be very fast.




回答2:


I know this is a day late and a dollar short but you can use robocopy for this purpose and it will list paths longer than 255 chars:

robocopy <SourceRoot> <DummyDestinationDir> /MIR /FP /NC /NS /NDL /NJH /NJS /LOG:<LogFilePath> /L

I know it's pretty wordy but robocopy is very quick compared to PowerShell, though I don't know how it would stack up against cmd's dir. You can either redirect std out using ">" or site the /LOG: parameter like above. I would test to see which is faster. Note do not use the /TEE option console output slows robocopy down in my experience. Also note the file paths will be indented in the output but this is easily rectified with a text editor than can trim leading and/or trailing whitespace.




回答3:


As Shay sys, Powwershell V3 is much better than v2.

If you just want a list of the file's fullnames, the legecy dir command with a /B (bare) switch is still faster than get-childitem

cmd /c dir <root path> /B /S /A-D


来源:https://stackoverflow.com/questions/15998312/powershell-fastest-directory-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!