Avoiding Jitter: Jumpstarting the Exchange shell
Published Aug 01 2008 01:20 PM 5,286 Views

A little trick from Jeffrey Snover over on PowerShell team blog: Speeding Up PowerShell Startup. Running the script mentioned by Jeffrey speeds up PowerShell startup times. Yes, hard to believe at first, but after having run this on a few servers, as Jeffrey says - the reaction is "Wow!"

  1. Paste the following in notepad and save it as Update-Gac.ps1 (or whatever you want to call it):

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

    Note: On x86 systems; replace Framework64 in the second line of this script with Framework.

  2. [Optional] Close all open windows
  3. [Optional] Start the Exchange Management Shell and note the time it takes to start up
  4. Run the script: .\Update-Gac.ps1 (or whatever you saved it as)
  5. Quit all open windows, start the Shell. Notice the difference?

As Jeffrey says in his blog post, the PowerShell team had a problem in Windows PowerShell v1, that caused the binaries not to be NGENed.

What's NGEN?

Managed code exists in Common Intermediate Language (CIL). The Just In Time (JIT) compiler takes that and converts it into native code for a particular processor/platform - a process also referred to as "jitter". If you don't want this translation to happen at runtime, you can use NGEN.exe - the Native Image Generator - to convert managed code from the CIL to native code. Native code does not need to be compiled at run time, and thereby avoids jitter.

So how does speeding up PowerShell help Exchange?

The Shell is built on Windows PowerShell technology, and under the hood, the Exchange Management Console also executes PowerShell cmdlets. If you're running Exchange Server 2007 on Windows Server 2003, you're likely to see performance gains in shell start-up times after running this script. On one of my Exchange 2007 servers, EMS now starts up in as little as 2-3 seconds. Disclaimer: Your mileage may vary.

Feel free to leave feedback about results you're seeing with this.

Bharat Suneja

Version history
Last update:
‎Aug 01 2008 01:20 PM
Updated by: