PowerShell 性能问题

标签 powershell batch-file

我是 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/

相关文章:

python - Powershell 输出为数组 (Python)

powershell - 区分注册表项和值路径

c# - 编译时从数据库获取dll版本号

Windows 批处理文件 - 在变量上查找字符串,查找包含百分比字符和单引号的字符串

batch-file - 如何使用 Sha256 证书为 .NET 4.0(如 Visual Studio Update 3)签署 ClickOnce

windows - 在类型命令批处理文件中隐藏文件名

vba - 如何在 VBA 中一个一个地执行多个批处理文件?

windows - 递归检查文件并在特定文件类型存在时执行压缩

powershell - 如何从 vNext 构建代理上的自定义脚本加载 PowerShell 模块?

Powershell:根据属性过滤属性