Powershell slow starting on Windows 10

10

4

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

mike

Posted 2017-05-24T14:31:33.227

Reputation: 131

You 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? – Julian Knight – 2017-05-24T14:33:57.913

6

powershell is always slow to start. But Ms ignores those complains and only response "powershell is fast"

– magicandre1981 – 2017-05-24T14:36:10.057

As You see -noprofile option is set. No difference. – mike – 2017-05-24T17:21:48.527

I see it. send this to MS, but they ignore any reports that powershell is slow – magicandre1981 – 2017-05-25T18:27:40.980

Yea, 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. – mike – 2017-05-25T20:39:16.247

1again, for me powershell is also always slow. ask this Microsoft. – magicandre1981 – 2017-05-26T15:41:55.037

70.2869261 seconds for me... if that makes you feel any better – KCD – 2019-06-05T02:23:36.110

Now I have 0,2915139 seconds. Windows 10 (1809) and that is ok! Solved after reinstall. – mike – 2019-06-06T07:22:42.280

Answers

2

What you could try is 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' çonsole which came with the fall update (Powershell was veeeerrrrry slow) With legacy on everything works fine again.

Peter Bakker

Posted 2017-05-24T14:31:33.227

Reputation: 21

2

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.

SliverNinja - MSFT

Posted 2017-05-24T14:31:33.227

Reputation: 188

1Perfect! 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! – Paras Shah – 2019-04-01T02:22:16.177

1

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/lzybkr/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).

takemyoxygen

Posted 2017-05-24T14:31:33.227

Reputation: 119

0

Instead of ngening every assembly powershell loaded, what I tend to do whenever I update Windows 10 is run ngen update:

. (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.

Carl Walsh

Posted 2017-05-24T14:31:33.227

Reputation: 151