Saturday, July 12, 2008

Make PowerShell start much faster

Jeffrey Snover recently wrote the following on the PowerShell Blog:

Speeding Up PowerShell Startup

I talked about this before but a number of people have missed it so here it is under a better title.

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. The instructions for how to fix this are HERE.

Source: http://blogs.msdn.com/powershell/archive/2008/07/11/speeding-up-powershell-startup.aspx

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

My personal advice would be for everyone to try out the "trick" - on some of my systems running the script reduced PowerShell startup time by 75% or more!

2 comments:

mnault_1982 said...

AWESOME.... It used to take about 30 seconds for my powershell to load the microsoft copyright and starting directory. Now it's up and running in 2 seconds. Great post! Keep 'em coming!

Interesting facts said...

Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.
ffmpeg hosting| html5 hosting