Home
%3CLINGO-SUB%20id%3D%22lingo-sub-585159%22%20slang%3D%22en-US%22%3EAvoiding%20Jitter%3A%20Jumpstarting%20the%20Exchange%20shell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-585159%22%20slang%3D%22en-US%22%3E%3CP%3E%3C%2FP%3E%3CP%3EA%20little%20trick%20from%20Jeffrey%20Snover%20over%20on%20PowerShell%20team%20blog%3A%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fpowershell%2Farchive%2F2007%2F11%2F08%2Fupdate-gac-ps1.aspx%22%20title%3D%22Go%20to%20Jeffrey's%20post%20on%20the%20PowerShell%20team%20blog%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ESpeeding%20Up%20PowerShell%20Startup%3C%2FA%3E.%20Running%20the%20script%20mentioned%20by%20Jeffrey%20speeds%20up%20PowerShell%20startup%20times.%20Yes%2C%20hard%20to%20believe%20at%20first%2C%20but%20after%20having%20run%20this%20on%20a%20few%20servers%2C%20as%20Jeffrey%20says%20-%20the%20reaction%20is%20%22Wow!%22%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EPaste%20the%20following%20in%20notepad%20and%20save%20it%20as%20Update-Gac.ps1%20(or%20whatever%20you%20want%20to%20call%20it)%3A%3CBR%20%2F%3E%3CP%20class%3D%22code%22%3ESet-Alias%20ngen%20%40(%3CBR%20%2F%3Edir%20(join-path%20%24%7Benv%3A%5Cwindir%7D%20%22Microsoft.NET%5CFramework64%22)%20ngen.exe%20-recurse%20%7C%3CBR%20%2F%3Esort%20-descending%20lastwritetime%3CBR%20%2F%3E)%5B0%5D.fullName%3CBR%20%2F%3E%5Bappdomain%5D%3A%3Acurrentdomain.getassemblies()%20%7C%20%25%7Bngen%20%24_.location%7D%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3A%3C%2FSTRONG%3E%20On%20x86%20systems%3B%20replace%20Framework64%20in%20the%20second%20line%20of%20this%20script%20with%20Framework.%3C%2FP%3E%0A%3C%2FLI%3E%0A%3CLI%3E%5BOptional%5D%20Close%20all%20open%20windows%3C%2FLI%3E%0A%3CLI%3E%5BOptional%5D%20Start%20the%20Exchange%20Management%26nbsp%3BShell%26nbsp%3Band%20note%20the%20time%20it%20takes%20to%20start%20up%3C%2FLI%3E%0A%3CLI%3ERun%20the%20script%3A%20.%5CUpdate-Gac.ps1%20(or%20whatever%20you%20saved%20it%20as)%3C%2FLI%3E%0A%3CLI%3EQuit%20all%20open%20windows%2C%20start%26nbsp%3Bthe%20Shell.%20Notice%20the%20difference%3F%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EAs%20Jeffrey%20says%20in%20his%20blog%20post%2C%20the%20PowerShell%20team%26nbsp%3Bhad%20a%20problem%20in%20Windows%20PowerShell%20v1%2C%20that%20caused%20the%20binaries%20not%20to%20be%20NGENed.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1563541470%22%20id%3D%22toc-hId-1591366420%22%3EWhat's%20NGEN%3F%3C%2FH3%3E%0A%3CP%3EManaged%20code%20exists%20in%20Common%20Intermediate%20Language%20(CIL).%20The%20Just%20In%20Time%20(JIT)%20compiler%20takes%20that%20and%20converts%20it%20into%20native%20code%20for%20a%20particular%20processor%2Fplatform%20-%20a%20process%20also%20referred%20to%20as%20%22jitter%22.%20If%20you%20don't%20want%20this%20translation%20to%20happen%20at%20runtime%2C%20you%20can%20use%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2F6t9t5wcf(VS.80).aspx%22%20title%3D%22Find%20out%20more%20about%20the%20Native%20Image%20Generator%20on%20MSDN%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3ENGEN.exe%3C%2FA%3E%20-%20the%20Native%20Image%20Generator%20-%20to%20convert%20managed%20code%20from%20the%20CIL%20to%20native%20code.%20Native%20code%20does%20not%20need%20to%20be%20compiled%20at%20run%20time%2C%20and%20thereby%20avoids%20%3CI%3Ejitter%3C%2FI%3E.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--988615491%22%20id%3D%22toc-hId--960790541%22%3ESo%20how%20does%20speeding%20up%20PowerShell%20help%20Exchange%3F%3C%2FH3%3E%0A%3CP%3EThe%20Shell%26nbsp%3Bis%20built%20on%20Windows%20PowerShell%20technology%2C%20and%20under%20the%20hood%2C%20the%20Exchange%26nbsp%3BManagement%20Console%26nbsp%3Balso%20executes%20PowerShell%20cmdlets.%26nbsp%3BIf%20you're%20running%20Exchange%20Server%202007%20on%20Windows%20Server%202003%2C%20you're%20likely%20to%20see%20performance%20gains%20in%20shell%20start-up%20times%20after%20running%20this%20script.%26nbsp%3BOn%20one%20of%20my%20Exchange%202007%20servers%2C%20EMS%20now%20starts%20up%20in%20as%20little%20as%202-3%20seconds.%20%3CB%3EDisclaimer%3C%2FB%3E%3A%20Your%20mileage%20may%20vary.%3C%2FP%3E%0A%3CP%3EFeel%20free%20to%20leave%20feedback%20about%20results%20you're%20seeing%20with%20this.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22author%22%3E%3CA%20href%3D%22http%3A%2F%2Fblogs.technet.com%2Farchive%2F2008%2F07%2F24%2F449351.aspx%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%20target%3D%22_blank%22%3EBharat%20Suneja%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

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
    )[0].fullName
    [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

20 Comments
Not applicable
Nice, from 40-50 odd seconds (cold start) to 17-20 seconds.
Not applicable
Definitely an improvement on my servers, thanks for the tip!

But what I'm really looking for is some major enhancements to the management console interface. Perhaps a sneak peak of what's to come with SP2? :)
Not applicable
Cool trick Bharat! I am going to try that on my Exchange servers to see.
BTW, where is my book? ;)
Not applicable
dude, that's cool.  definitely sped things up for my home test environment running on a mac mini.  every second counts, and I counted from 12 secs with jitter to 4 without.
Not applicable
From 30 seconds to less than 5. Great, but why isn't this run as part of the setup process? And why is the code not native in the first place if pretty much every Exchange server in existence is x64/x86...?
Not applicable
You mention Windows 2003.  Is this also applicable on Windows 2008, or is it builtin or something?
Not applicable
I get a lot of errors about not being able to locate Exchange related assemblies - mainly because it's looking for things that are not filenames. Running this under a standard powershell session on the other hand, does wonders.

We've had this script in our script repository for a good while now, and it's semi-standard practice to run it during the build of a new system.

@Kelvin: As I understand it, it's a 'bug' in the way powershell is installed that causes this process to not get run when it normally would. I believe it's fixed in v2.
Not applicable
Ran as instructed but no real improvement.  But then again my shells were already opening in 3-5 seconds.
Not applicable
Ran the script and wow! PS load times went from 30-40 seconds to less than 5 seconds.
Not applicable
Can someone confirm that applying this wont cause problems when we come to apply exchange patchesservice packspowershell updates? Will the newer assemblies that come along with any patches "overwrite" the ones that have been etched into the gac without errors and calls to PSS?
Not applicable
@Kelvin: As stated in Jeffrey's post, it's a PowerShell v1.0 issue, corrected in PS v2.0.
(Note, Exchange Server 2007 requires PS v1.0.)

@Mark: This simply performs the task of compiling to native code in advance, rather than at run time. You should not have issues with patches as a result of this.
Not applicable
Are you guys running this script in the EMS or just standard PowerShell?

If you run this script in EMS, you get heaps of errors on 'assemblies unable to load' and 'file not found' errors. If you run this in standard PowerShell, you don't get any errors, and the script finishes in a few seconds.

Either way, the EMS and EMC startup times have not improved for me. It's still 40-50sec slow. Am I somehow screwing up in executing the script?!
Not applicable
hi Bharat..is there also a way to "undo" this change for powershell once this has been done?
Not applicable
Fantastic!  Speed up several servers from 30-45 seconds to less than 5!  As Steve said above, run the script from the standard PowerShell prompt to avoid the errors.
Not applicable
@Steve: The errors can be safely ignored.

@Satguru: Investigating if there's a way to "undo" - although I haven't come across a situation where this would be required. Will post update in these comments if I have something to report. :)
Not applicable
It took me at first 10 seconds to start, now 5. Not a really important improvement, but oh well, it saves me some lifetime in total over a year :)
Thank you for the script.
Not applicable
this seems to speed up DPM 2007 mgmt shell also. cool.
Not applicable
Thks!!!!
Not applicable
nice.... what's the code to disable?
Not applicable