Friday, August 23, 2013

speeding up Powershell Get-ChildItem

This Windows Powershell blog entry explains why Get-ChildItem is so slow, especially over networks. The fast workaround for now is to use the old cmd.exe
cmd.exe /c dir
The disadvantage is that your output comes back as one string per line, so you'll need to parse out the results. Here's an example including a network path and output that makes the results a little more helpful after noting that the header and footer information from the command all starts with whitespace
cmd.exe /c dir \\myserver\myshare\*.csv | where {$_[0] -ne ' '}
12/09/2012 02:06 PM 879,703 SOMEFILE.csv
07/08/2013 09:16 AM 61,293 SOMEOTHERFILE.csv

No comments:

Post a Comment