Speed up PowerShell startup with Update-Gac.ps1 script

Jeffrey Snover, Windows Management Partner Architect, reports that —”in V1, we had a problem which caused our assemblies to not get ngen'ed during installation.  If you don't know what "ngen" is, don't worry - you don't need to.  All you need to know is that we didn't do the step that makes things go fast […]

Jeffrey Snover, Windows Management Partner Architect, reports that —”in V1, we had a problem which caused our assemblies to not get ngen'ed during installation.  If you don't know what "ngen" is, don't worry - you don't need to.  All you need to know is that we didn't do the step that makes things go fast on your machine.”

Below is the content of the Update-GAC.ps1 script that I run whenever I install a new version of PowerShell. Our installation is supposed to ngen the assemblies in the background. If that works, it doesn't work fast enough for me. Also I've seen lots of examples where people run this script long after their install and things get a TON faster so …. The install team is looking into the issue but until then:

Set-Alias ngen @(
dir (join-path ${env:\windir} "Microsoft.NET\Framework") ngen.exe -recurse |
sort -descending lastwritetime
)[0].fullName
[appdomain]::currentdomain.getassemblies() | %{ngen $_.location}