Possible Windows PowerShell speedup

Windows PowerShell is used by PhotoStructure to extract a bunch of volume and system metadata, as well as perform some file operations.

Unfortunately, PowerShell is far-reaching, and can be slowed down (dramatically!) simply by applying windows updates.

PhotoStructure already avoids slowdowns due to profile additions (via the powerShellArgs setting, but on my older windows test box, I found that PowerShell could take north of 10 seconds to launch, even skipping my (empty) profile.

I found this StackOverflow post which helped me. Here’s the gist:

  1. Tap the Windows key, type powershell, and pick Run as Administrator:

  1. Paste the following into the terminal window:
$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

What does this do?

Remember: never run any terminal command without understanding what it does!

This snippet tells ngen.exe to recompile the installed .NET components.

Windows Updates should do this automatically, but on my box, it didn’t, and my pwsh startup dropped from 15 seconds to just a couple milliseconds, which noticeably sped up almost all PhotoStructure components: the setup page, the about page, and even sync are noticeably faster on this machine now that PowerShell is performant.

See also