[英]powershell.exe call from batch file unbearable slow after upgrading to windows 10
从Win7迁移到Win10(1607 LTSB)之后,我的构建过程中出现了.bat
- > .ps1
调用问题 - 在Win7上调用PowerShell,在Win7上花费不到100毫秒,现在在某些主机上需要10秒+ :-(
调用如下所示: powershell -ExecutionPolicy Bypass -NonInteractive %scriptfile%
从开始菜单启动ISE和PowerShell.exe的性能很好。
到目前为止,我无法挖掘任何有用的东西......
我创建了一个小助手脚本,从不同的起点测量PowerShell的启动性能: https ://gist.github.com/mwallner/d3c86794bb74680b0c0cf4e9a9758ab4在Win7和我的大多数Win10机器启动时都没有运气低于1秒。
这里有谁已经解开了这个谜语?
解决了! - 它一直是UAC :-(
解决方案:为正在运行scriots的用户禁用UAC,或确保调用其他脚本的第一个脚本以管理员/提升方式运行。
不确定为什么UAC会导致这些延迟,我确信有些情况下这不是一个选项 - 但对我来说,这可以通过确保第一个脚本被提升+禁用UAC for dev box来解决。
我遇到了类似的问题 - 脚本需要多秒才能启动。
问题结果是两个因素的组合:
ExecutionPolicy
强制设置为RemoteSigned
(运行Get-ExecutionPolicy -List
并检查MachinePolicy
的值) ...所以它通过重新启动来修复。 (我认为覆盖GPO设置值也可以,但我没有尝试过。)
什么行不通:
powershell -NoProfile
) $PSModuleAutoloadingPreference = 'none'
禁用模块自动加载(在v3中引入) ,即powershell.exe -NoProfile -ExecutionPolicy Bypass -command "$PSModuleAutoloadingPreference = 'none'; & path\\to\\script.ps1"
我注意到只是运行PowerShell相对较快,只有脚本执行(通过命令行参数或&
/ Call运算符 )很慢。 例如,我可以通过将它运行到powershell的stdin来运行脚本,这不会导致减速:
type "script.ps1" | powershell.exe -noprofile -nologo -executionpolicy Bypass -file -
此时我尝试使用ProcMon进行故障排除 ,但没有显示任何长时间的呼叫。
接下来,我尝试打开Process Explorer来检查powershell.exe进程在加载脚本时的堆栈。 堆栈的顶部是:
ntdll.dll!RtlGetNativeSystemInformation+0x14
KERNEL32.DLL!lstrcmpA+0x12d
KERNEL32.DLL!CreateToolhelp32Snapshot+0x108
[Native Frame: IL Method without Metadata]
[Managed to Unmanaged Transition]
System.Management.Automation.dll!System.Management.Automation.PsUtils.GetParentProcess+0x73
System.Management.Automation.dll!System.Management.Automation.Internal.SecuritySupport.GetExecutionPolicy+0x138
这让我发出#2578 ,解释了我所看到的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.