Skip to content

Instantly share code, notes, and snippets.

@boredwz
Last active May 16, 2025 21:28
Show Gist options
  • Select an option

  • Save boredwz/d0bbbd334d49db294d85cebf6b5b19ec to your computer and use it in GitHub Desktop.

Select an option

Save boredwz/d0bbbd334d49db294d85cebf6b5b19ec to your computer and use it in GitHub Desktop.
PowerShell slow startup fix
<# USAGE:
& $([scriptblock]::Create((iwr -useb 'https://gist.githubusercontent.com/boredwz/d0bbbd334d49db294d85cebf6b5b19ec/raw/powershell_slow_startup_fix.ps1')))
#>
#requires -Version 5
# Elevate
iwr -useb 'https://gist.githubusercontent.com/boredwz/f7e908dd8d25cc8345ef2065e093d63c/raw/admin.ps1' | iex
If (!(Admin)) {
Write-Warning 'Administrator rights required.';'Press [Enter] or [Y] to run as Admin...'
if([Console]::ReadKey($true).Key -match '^(Enter|Y)') {Admin -Elevate $MyInvocation.Line};return
}
# https://stackoverflow.com/a/59343705
# Generate native images for an assembly and its dependencies and install them in the Native Images Cache.
$env:PATH = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
[AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object {
$path = $_.Location
if ($path) {
$name = Split-Path $path -Leaf
Write-Host -ForegroundColor Yellow "`r`nRunning ngen.exe on '$name'"
ngen.exe install $path /nologo
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment