Powershell slow starting on Windows 10
Solution 1
This was happening to me also - though maybe not the best route, adding powershell.exe
to the list of Windows Defender exclusions sped it up from 20 seconds to < 1 second.
Using legacy console, purging PSReadLine, and running ngen did not seem to help at all.
Solution 2
I had been experiencing the same issue for quite some time until PowerShell started failing on startup with the following error:
Exception:
System.OutOfMemoryException: Array dimensions exceeded supported range.
at System.Collections.Generic.List`1.set_Capacity(Int32 value)
at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
at System.Collections.Generic.List`1.Add(T item)
at System.IO.File.InternalReadAllLines(String path, Encoding encoding)
at Microsoft.PowerShell.PSConsoleReadLine.<ReadHistoryFile>b__67_0()
at Microsoft.PowerShell.PSConsoleReadLine.WithHistoryFileMutexDo(Int32 timeout, Action action)
at Microsoft.PowerShell.PSConsoleReadLine.DelayedOneTimeInitialize()
at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------
This led me to the existing Github issue: https://github.com/Powershell/PSReadLine/issues/673
I tried deleting history file in ~\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\
which was over 6 GB by then and after that PowerShell console started opening pretty quickly.
Maybe the slowness you experience is the PowerShell trying to read a big history file (which is not yet big enough to cause OutOfMemory
).
Solution 3
What you could try is to create a shortcut to powershell.exe
, right-click on it > properties, go to tab options, click on "use legacy console". My screenreader (magic and zoomtext) couldn't stand the 'new' console which came with the fall update (Powershell was veeeerrrrry slow) With legacy on everything works fine again.
Solution 4
There can be other reasons for what causes slow Powershell start, but something that always causes slowdown for me is Windows update.
Instead of running ngen
on every assembly powershell happens to have loaded, what I want to do is run ngen update
which optimises every globally installed assembly:
. (Join-Path ([Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()) ngen.exe) update
After updating to May 2019 Win10, I see that improved the performance of
(measure-command { powershell.exe -command "1+1" }).TotalSeconds
from ~1.35s to ~0.55s.
Solution 5
After analize powershell.exe with procmon (sysinternals tool) I could see that the process was trying to do something in catroot2 folder, so after rename it (you have to stop the CryptSvc service that blocks the folder), it was created automatically. So the conclusion is that folder got corrupted. (Sorry for my bad English)
Execute the next .bat
net stop CryptSvc /y
rename c:\windows\system32\catroot2 Catroot2.bak
net start CryptSvc
Related videos on Youtube
mike
Updated on September 18, 2022Comments
-
mike almost 2 years
I have problem with slow starting of powershell prompt on Windows 10 ( Version 1703 - Creators Update ).
My hw specs ( quite fast machine ): Intel i5-7440HQ (Quad Core) / 32GB DDR4 RAM / 512 Samsung SSD hard drive.
I tried to bypass profile and execution policy but it does not change anything:
powershell -noprofile -ExecutionPolicy Bypass ( Measure-Command { powershell "Write-Host 1" } ).TotalSeconds
6,228067
My friends same laptop with Windows 10 without Creators Update runs powershell in less than 0,5 sec.
Also tried do some compilation with ngen.exe but it didn't help:
$env:path = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory() [AppDomain]::CurrentDomain.GetAssemblies() | % { if (! $_.location) {continue} $Name = Split-Path $_.location -leaf Write-Host -ForegroundColor Yellow "NGENing : $Name" ngen install $_.location | % {"`t$_"} }
Any idea how may I investigate this issue?
Greetings
-
Julian Knight about 7 yearsYou should start by checking your profile script to see if anything is running in there that is delaying startup. My output is 1.2774795 seconds. Also, what machine, processor, memory, other things running?
-
magicandre1981 about 7 yearspowershell is always slow to start. But Ms ignores those complains and only response "powershell is fast"
-
mike about 7 yearsAs You see -noprofile option is set. No difference.
-
magicandre1981 about 7 yearsI see it. send this to MS, but they ignore any reports that powershell is slow
-
mike about 7 yearsYea, but explain me how same laptop ( both ordered same specs ) starts powershell in less than 0,5 s and mine over 6 s? Difference is for sure that my is with Creators Update and the second one is without this update. I tried to use also Process Monitor looking for powershell.exe process, but nothing happen for 6 s and then all is in log.
-
magicandre1981 about 7 yearsagain, for me powershell is also always slow. ask this Microsoft.
-
KCD about 5 years
70.2869261
seconds for me... if that makes you feel any better -
mike about 5 yearsNow I have 0,2915139 seconds. Windows 10 (1809) and that is ok! Solved after reinstall.
-
-
Paras Shah over 5 yearsPerfect! This did the trick. I had an issue similar to yours where the window would open up but the path wouldn't load for more than 30 seconds. As soon as I excluded it from Defender, it loaded in a snap. Thanks a lot!
-
Tomas Jansson almost 4 yearsSounds like what I need. Did you add the exclusion as a file exclusion?
-
Toto over 2 yearsCode without any explanation is useless. Can you elaborate on this a little more?