回答
除了尽量减少你把你的各种配置文件脚本的内容(如下图所示),没有什么可以做:
C:\PS> $profile | fl * -force
AllUsersAllHosts : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts : C:\Users\hillr\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\hillr\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
一种方式进行检查,看是否型材脚本导致滞后是使用-noprofile选项启动powershell。如果启动时间不同,则由于您的配置文件脚本。您可以使用.NET秒表,像这样:
function TimeThis([scriptblock]$scriptblock, $msg)
{
if (!$stopWatch)
{
$script:stopWatch = new-object System.Diagnostics.StopWatch
}
$stopWatch.Reset()
$stopWatch.Start()
. $scriptblock
$stopWatch.Stop()
if ($msg -eq $null) { $msg = "$scriptblock" }
"Execution time: $($stopWatch.ElapsedMilliseconds) mS for $msg"
}
. TimeThis {Import-Module $Module -args ~\Pscx.UserPreferences.ps1}
虽然你可以使用测量命令时,它并没有显示什么是执行,你没有命令输出(只在一个非常详细的时尚时间)。
那里曾经是在早期的CTP一个问题,即安装程序不会NGEN PowerShell的组件以及其他可能导致显着的加载时间延迟。不过,我非常肯定,在最终的2.0安装(以及Windows 7和Windows Server 2008 R2内置的PowerShell)中已经修复了这个问题。如果后续的目录及其内容存在,您应该ngen'd:
dir 'C:\Windows\assembly\NativeImages_v2.0.50727_32\Microsoft.PowerShel#' -r
追查性能问题这样可能会非常棘手,但也有一些事情可以做,以改善/解决的事情。
首先,启动PowerShell冷与热。至少在我的工作站上,第一次在早上运行PS时,启动时间比后续时间要长。有没有办法让它保持温暖以最小化加载时间?
其次,使用像Process Monitor从Windows Sysinternals工作的罚款乡亲的工具。将其设置为监视powershell.exe进程,并查看它正在做什么,这是很长的。对我而言,我有许多来自网络的映射网络驱动器和共享脚本。在我的测试中,我测量了每次启动的每个远程脚本在启动时的延迟时间为2秒。
PowerShell中确实需要从磁盘加载大量资源到内存中,所以应该不用说,有你的I/O系统达到最佳性能也将有所帮助。碎片整理,确保你有足够的免费内存等,它甚至从注册表中查询一些,所以你可能想要确保你的registry is completely defragged - 虽然这是一个相当长的镜头。
Goyuix,谢谢你指出要调查的各个领域。 +1 – MagicAndi 2010-05-15 00:15:54
它可能是完全不相关的,但我曾经在PowerShell启动过程中有过一次大规模的停顿。
它在某种程度上涉及到的事实,我的笔记本电脑是在一个领域,我再休眠,并再次启动它时,笔记本电脑,该域名是不是了。我用dottrace看了一下这个初创公司,只能看到在提供商的初始化过程中,代码被卡住了。
在这种情况下重新启动机器。也不总是发生(事实上,迄今为止只有一次)。
使用内嵌C#加速X100最大
添加型-language CSharpVersion3 @ “
”@
添加型@“
” @
如果可以不使用-TypeDefinition @”
使用32位的powershell
加速×1.5
PS-run.cmd:
SET PS32 =%WINDIR%\ Syswow64资料\ WindowsPowerShell \ v1.0 \ powershell
%PS32%。\%*
- 1. 您可以在PowerShell v2脚本中设置对象的DefaultDisplayPropertySet吗?
- 2. 增加PowerShell V2中的并发shell数
- 3. 加速sql脚本?
- 4. 加速Bash脚本
- 5. PowerShell v2添加打印机
- 6. 加速UrlFetch Google App脚本?
- 7. 加速此vba脚本
- 8. 日志中的PowerShell脚本
- 9. Pentaho中的PowerShell脚本
- 10. PostBuild中的PowerShell脚本
- 11. PowerShell脚本中的更正
- 12. C#powershell脚本
- 13. 用PowerShell脚本
- 14. Outlook Powershell脚本
- 15. Elevate PowerShell脚本
- 16. 加速powershell的remove-netfirewallrule
- 17. Powershell调用Powershell脚本
- 18. 需要更快速地在PowerShell脚本中进行搜索
- 19. TFS版本定义中的Powershell脚本
- 20. 将日志记录快速添加到现有的PowerShell脚本集
- 21. 从PowerShell终端添加到Python脚本?
- 22. 尝试添加回车到powershell脚本
- 23. 加快PowerShell脚本运行时
- 24. 将powershell脚本添加到C#代码
- 25. Wix Run Powershell脚本
- 26. 签署PowerShell脚本
- 27. 错误PowerShell脚本
- 28. SSIS PowerShell脚本EXECUTE
- 29. PowerShell脚本查询
- 30. 通过PowerShell脚本
Keith,被接受为答案。抱歉耽搁了! – MagicAndi 2010-05-22 12:15:13
有没有办法ngen模块加载模块?如PowerTab和PS社区扩展? – 2010-08-23 14:36:38
是的,但手动。找到您加载的模块所需的托管dll,并在其上运行ngen.exe。使用2.0框架中的ngen.exe 'C:\ WINDOWS \ Microsoft.NET \ Framework64 \ v2.0.50727'。 – 2010-08-23 14:50:38