Update-Gac.ps1

Update-Gac.ps1

  • Comments 39

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 – here is the script I use:

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

<Update 12/4/008> NOTE - there is a updated (and better) version of this script HERE.

Cheers!

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Leave a Comment
  • Please add 1 and 6 and type the answer here:
  • Post
  • One can also determine the .NET framework install path using RuntimeEnvironment.GetRuntimeDirectory()

    http://blogs.msdn.com/kirillosenkov/archive/2008/05/07/how-to-determine-the-net-installation-directory-and-clr-version.aspx

  • I tried this Script and it does not do any thing to speed the start-up of poweshell console for Exchange 2007 installed on a Windows Server 2008!!! Any idea on how to fix this??

    Thanks.

  • Jeffrey Snover just dropped this little gem into the " PowerShell: Creating Manageable Web Services "

  • I ran the script in V2, still takes on the order of 15-20 seconds to get to PS when issuing powershell.exe from cmd.  I'm worried about the scripting speed.  I need to poll 300 machines repeatedly for very specific info.  It's starting to sound like I need to use a binary or maybe wscript

  • @Josh

    That doesn't sound right - we should be able to meet your needs.  Can you do the following and post it:

    1..10 | %{Measure-Command {powershell exit}}|ft totalseconds

    gwmi win32_processor |fl name,NumberOfCores,MaxClockSpeed,L2CacheSize

    gwmi Win32_PhysicalMemory |ft tag,speed,{$_.capacity/1mb} -auto

    Thanks!

    jps

  • Even after running this script my powershell takes > 20 seconds to start (either from shortcut or by typing powershell from cmd).  Starting it from within powershell itself is fast.

    Here is the output from the commands Josh suggested:

    PS C:\Documents and Settings\jdease>  1..10 | %{Measure-Command {powershell exit}}|ft totalseconds

                                                                                                              TotalSeconds

    ------------

    0.6983097

    0.6771509

    0.7174827

    0.6861359

    0.6862929

    0.7018789

    0.6871349

    0.6774461

    0.6860443

    0.6863205

    PS C:\Documents and Settings\jdease> gwmi win32_processor |fl name,NumberOfCores,MaxClockSpeed,L2CacheSize

    name          : Intel(R) Core(TM)2 CPU          6400  @ 2.13GHz

    NumberOfCores : 2

    MaxClockSpeed : 2128

    L2CacheSize   : 2048

    PS C:\Documents and Settings\jdease> gwmi Win32_PhysicalMemory |ft tag,speed,{$_.capacity/1mb} -auto

    tag               speed $_.capacity/1mb

    ---               ----- ---------------

    Physical Memory 0   667            1024

    Physical Memory 2   667            1024

  • Mine went to .5 secs

    don't know what it was before, but this put some pep in it's step (both ways)

  • Sorry to open an old topic, but I have a single server, having real problems opening powershell.  I have run the script attached to this thread, and it does throw errors trying to load the pscx.dll:

    Installing assembly C:\Program Files (x86)\PowerShell Community Extensions\Pscx.dll

    Failed to load dependency Pscx.Core of assembly Pscx, Version=1.1.1.0, Culture=neutral, PublicKeyToken=null because of t

    he following error : The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

    The script did not improve loading times (3+ seconds).  here is oupt from JPS's information script (put noprofile in, as my profile adds some overhead):

    PS C:\> 1..10 | %{Measure-Command {powershell -noprofile exit}}|ft totalseconds

    TotalSeconds

    ------------

      3.8922882

      3.2950101

      3.4424849

      3.4869485

       3.448749

      3.2428333

      3.2916778

       3.179595

      3.5320035

       3.352735

    PS C:\> gwmi win32_processor |fl name,NumberOfCores,MaxClockSpeed,L2CacheSize

    name          : Intel(R) Xeon(R) CPU           E5320  @ 1.86GHz

    MaxClockSpeed : 1863

    L2CacheSize   : 0

    name          : Intel(R) Xeon(R) CPU           E5320  @ 1.86GHz

    MaxClockSpeed : 1863

    L2CacheSize   : 0

    name          : Intel(R) Xeon(R) CPU           E5320  @ 1.86GHz

    MaxClockSpeed : 1863

    L2CacheSize   : 0

    name          : Intel(R) Xeon(R) CPU           E5320  @ 1.86GHz

    MaxClockSpeed : 1863

    L2CacheSize   : 0

    PS C:\> gwmi Win32_PhysicalMemory |ft tag,speed,{$_.capacity/1mb} -auto

    tag               speed $_.capacity/1mb

    ---               ----- ---------------

    Physical Memory 0                  4096

    I tried running the script inside of powershell, and launched from a script.  I tried with and without PSCX installed.  I made sure to point to the correct framework directory (x64).  I cant get powershell to load in under 3 seconds.

    Thanks,

    Jason

  • I finally tracked down the reason for my problems.  I am using signed scripts, and have set up an internal certificate server for the code signing cert.  The server does not have the required access to that server.  The code signing cert I created has references to the CRL as:

    URL=http://<certserver>/certenroll/<caname>.crl.  

    I needed to add permissions to that crl for everyone (off domain), and add firewall rules on port 80.  

    The server was not able to cache the CRL.

Page 3 of 3 (39 items) 123