Skip to content
Snippets Groups Projects

Optimize Powershell

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Steffen Heuschkel
    Edited
    optimize.ps1 629 B
    function Optimize-PowershellAssemblies {
      # NGEN powershell assembly, improves startup time of powershell by 10x
      $old_path = $env:path
      try {
        $env:path = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
        [AppDomain]::CurrentDomain.GetAssemblies() | % {
          if (! $_.location) {continue}
          $Name = Split-Path $_.location -leaf
          if ($Name.startswith("Microsoft.PowerShell.")) {
            Write-Progress -Activity "Native Image Installation" -Status "$name"
            ngen install $_.location | % {"`t$_"}
          }
        }
      } finally {
        $env:path = $old_path
      }
    }
    Optimize-PowershellAssemblies
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment