我是 Powershell 的新手。我使用以下 powershell 脚本从网络共享复制文件,但与传统的 Windows 批处理文件相比,时间成本长得离谱。可能是什么原因?
$dlls=get-childitem -path "\\myShare\myBinFolder" -include *.dll -recurse
copy-item $dlls -destination c:\bins
谢谢
更新 - 2011 年 1 月 13 日下午 1 - 1:38
为什么 Get-ChildItem 这么慢?
http://blogs.msdn.com/b/powershell/archive/2009/11/04/why-is-get-childitem-so-slow.aspx
最佳答案
不要使用Include
参数。请改用 Filter
参数。 Include 将要求从共享中返回每个文件并在本地进行过滤。使用 Filter
应该允许在远程端进行过滤。
$dlls = Get-ChildItem -Path "\\myShare\myBinFolder" -Filter *.dll -recurse
或者使用这些参数的位置特征:
$dlls = Get-ChildItem \\myShare\myBinFolder *.dll -r
事实上,我唯一会在 Filter
上使用 Include
的情况是我需要指定多个过滤条件(Include 采用字符串数组),例如:
Get-ChildItem . -inc *.h,*.cpp,*.rc -r
关于PowerShell 性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4676977/