From 50fbe1fa14b784c5b3963bb269b0269e38c11513 Mon Sep 17 00:00:00 2001
From: simeononsecurity <4913771+simeononsecurity@users.noreply.github.com>
Date: Mon, 2 Oct 2023 19:55:37 +0000
Subject: [PATCH] Update windows11.ps1

---
 windows11.ps1 | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/windows11.ps1 b/windows11.ps1
index 041ffae..c4c9198 100644
--- a/windows11.ps1
+++ b/windows11.ps1
@@ -1,3 +1,22 @@
+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
+
 Start-Job -Name "Install and Configure Chocolatey" -ScriptBlock {
     Write-Host "Installing Chocolatey"
     # Setting up directories for values