PowerShell steps to fix slow startup
When PowerShell starts to become slow at startup, an update of the .NET framework might be the cause.To speed up again, use ngen.exe
on PowerShell's assemblies.It generate native images for an assembly and its dependencies and install them in the Native Images Cache.
Run this as Administrator
$env:PATH = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()[AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object { $path = $_.Location if ($path) { $name = Split-Path $path -Leaf Write-Host -ForegroundColor Yellow "`r`nRunning ngen.exe on '$name'" ngen.exe install $path /nologo }}
Hope that helps
Step 1: Stop using PowerShell
.
Now, seriously, something that needs ~13 seconds (YMMV) on an quad-core i7 cpu to launch off an ssd drive is an abomination of software architecture.
But yes, I hear you, "no viable alternative" etc...
... but if forced, bribed or blackmailed to still use it, check if your Windows has DNS cache service enabled.
For me, with DNS cache disabled and powershell executable firewalled, the built-in 5.1.19041.906
version starts quickly, but the new pwsh 7.1.4
would take around 13 seconds to get responsive to keyboard input under same circumstances. It's so desperate to call home that it would just synchronously wait for some network timeout while blocking all user input, as if threads were a thing for the weak.
My resolution was to stick with the olden powershell 5.