I'm having some trouble with a .bat
->.ps1
call in my build process after moving from Win7 to Win10 (1607 LTSB) - the call to PowerShell, that took less than 100msec on Win7 now takes 10sec+ on Win10 on certain hosts :-(
The call looks like this: powershell -ExecutionPolicy Bypass -NonInteractive %scriptfile%
Startup-performance of ISE and PowerShell.exe from start-menu is good.
I wasn't able to dig up anything helpful so far...
I've create a little helper script that measures startup-performance of PowerShell from different starting points: https://gist.github.com/mwallner/d3c86794bb74680b0c0cf4e9a9758ab4 no luck with this either, on Win7 and most of my Win10 machines startup-time is way below 1sec.
anybody here who has already solved this riddle?
Solved! - it's been UAC all along :-(
Solution: disable UAC for the user that's running the scriots or make sure the first script that calls the others is being run as administrator / elevated.
Not sure why UAC is causing these delays, and I'm certain there are cases where this is not an option - but for me this is solved by ensuring the first script is elevated + disabling UAC for dev boxes.
I had a similar problem - scripts taking multiple seconds to start.
The problem turned out to be a combination of two factors:
ExecutionPolicy
force-set to RemoteSigned
via GPO (run Get-ExecutionPolicy -List
and check the value for MachinePolicy
)...so it was fixed by a restart. (I think overriding the GPO-set value would also work, but I didn't try it.)
What didn't work:
powershell -NoProfile
)$PSModuleAutoloadingPreference = 'none'
, i.e. powershell.exe -NoProfile -ExecutionPolicy Bypass -command "$PSModuleAutoloadingPreference = 'none'; & path\to\script.ps1"
I noticed that simply running PowerShell was relatively fast, only script execution (via command-line parameters or the &
/ Call operator) was slow. For instance I could run the script by piping it to powershell's stdin, which didn't incur the slowdown:
type "script.ps1" | powershell.exe -noprofile -nologo -executionpolicy Bypass -file -
At this point I tried troubleshooting with ProcMon, which didn't show any long calls.
Next I tried opening Process Explorer to check the stack of the powershell.exe process while it was loading the script. The top of the stack was:
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
which led me to issue #2578 that explained the behavior I was seeing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With