{"id":11040,"date":"2025-09-03T10:01:00","date_gmt":"2025-09-03T10:01:00","guid":{"rendered":"https:\/\/cheapwindowsvps.com\/blog\/how-to-fix-slow-startup-times-for-powershell-console-and-scripts\/"},"modified":"2025-09-03T10:01:00","modified_gmt":"2025-09-03T10:01:00","slug":"how-to-fix-slow-startup-times-for-powershell-console-and-scripts","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/how-to-fix-slow-startup-times-for-powershell-console-and-scripts\/","title":{"rendered":"How to Fix Slow Startup Times for PowerShell Console and Scripts"},"content":{"rendered":"<p>I have observed that the PowerShell console can be slow to open across various computers, sometimes taking several minutes. This slow start impacts not only the command shell (powershell.exe or pwsh.exe) but also the execution of logon PowerShell scripts via Group Policy Objects (GPO) or scheduled tasks. In this piece, we will explore possible causes for the sluggish startup and methods to reduce loading time.<\/p>\n<h3>Common Causes for Slow PowerShell Startup<\/h3>\n<ol>\n<li><strong>User-defined Functions<\/strong>: Functions defined in PowerShell profile files are reloaded every time the PowerShell process starts.<\/li>\n<li><strong>Excessive PS Modules<\/strong>: A large number of installed modules that load automatically can delay startup.<\/li>\n<li><strong>PSReadLine History<\/strong>: The PSReadLine module may attempt to load an overly large history file.<\/li>\n<li><strong>.NET Framework Issues<\/strong>: Conflicts or corruption in .NET Framework components can introduce significant delays.<\/li>\n<\/ol>\n<h3>Measuring PowerShell Load Time<\/h3>\n<p>The <strong>Measure-Command<\/strong> cmdlet provides insight into how long it takes for PowerShell to load. Execute the following command to check load time:<\/p>\n<pre><code class=\"language-powershell\">powershell -noprofile -ExecutionPolicy Bypass ( Measure-Command { powershell &quot;Write-Host 1&quot; } ).TotalSeconds<\/code><\/pre>\n<p>If the load time exceeds 500 ms, PowerShell will log:<\/p>\n<pre><code>Loading personal and system profiles took XXX ms<\/code><\/pre>\n<p>For example, a startup time of 12 seconds signals slow executing code in profile files, indicating a possible problem.<\/p>\n<h3>Checking Profile Files<\/h3>\n<p>To compare startup speeds, you can run PowerShell without loading profiles using the options <code>-noprofile<\/code> for PowerShell or <code>-noProfile<\/code> for PowerShell Core.<\/p>\n<p>To list all profile files used during the startup, run the command:<\/p>\n<pre><code class=\"language-powershell\">$profile | select *<\/code><\/pre>\n<p>You can also check the contents of the profile files using:<\/p>\n<pre><code class=\"language-powershell\">Get-Content $PROFILE.AllUsersAllHostsGet-Content $PROFILE.AllUsersCurrentHostGet-Content $PROFILE.CurrentUserAllHostsGet-Content $PROFILE.CurrentUserCurrentHost<\/code><\/pre>\n<p>Review these files for unnecessary commands or functions and optimize where possible.<\/p>\n<h3>Managing PS Modules<\/h3>\n<p>Examine the installed modules, as a large collection could impede startup speed. List available modules with:<\/p>\n<pre><code class=\"language-powershell\">Get-Module -ListAvailable<\/code><\/pre>\n<p>To remove unused modules, employ:<\/p>\n<pre><code class=\"language-powershell\">Remove-Module -Name ModuleNameUninstall-Module -Name ModuleName -AllVersions -Force<\/code><\/pre>\n<p>Analyze the loading time of each module using:<\/p>\n<pre><code class=\"language-powershell\">Measure-Command { Import-Module ModuleName -Force }<\/code><\/pre>\n<p>Consider preventing automatic loading of all PS modules by adding:<\/p>\n<pre><code class=\"language-powershell\">$PSModuleAutoLoadingPreference = 'None'<\/code><\/pre>\n<h3>Addressing Other Possible Issues<\/h3>\n<ol>\n<li>\n<p><strong>VMware PowerCLI Delays<\/strong>: If you are using the VMware Infrastructure Management module, it might delay loading due to CRL checks. You can disable CRL checking through the registry or in the Internet Properties applet.<\/p>\n<\/li>\n<li>\n<p><strong>Antivirus Software<\/strong>: Sometimes, antivirus software may delay the startup. To check which DLLs are loaded during startup, run:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"language-cmd\">powershell.exe -c &quot;Write-Host $PID;Start-Sleep -s 60&quot;<\/code><\/pre>\n<p>Then, in a new PowerShell session, use:<\/p>\n<pre><code class=\"language-powershell\">Get-Process | where {$_.Id -eq &lt;YOUR_PID&gt;} | select -ExpandProperty modules<\/code><\/pre>\n<p>If your antivirus library is present, add exclusions for the PowerShell processes.<\/p>\n<ol start=\"3\">\n<li><strong>Accelerate .NET Framework Operations<\/strong>: Improve .NET Framework performance by compiling assemblies into native machine code using <code>ngen.exe<\/code>. Use the following command:<\/li>\n<\/ol>\n<pre><code class=\"language-powershell\">$env:PATH = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()[AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object {    $path = $_.Location    if ($path) {        $name = Split-Path $path -Leaf        Write-Host -ForegroundColor Yellow &quot;`r`nRunning ngen.exe on '$name'&quot;        ngen.exe install $path \/nologo    }}<\/code><\/pre>\n<ol start=\"4\">\n<li><strong>Process Monitor<\/strong>: Finally, consider using Process Monitor to identify any operations causing significant delays when starting PowerShell.<\/li>\n<\/ol>\n<p>By employing these strategies, you can address the common issues related to slow PowerShell startup and enhance its performance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have observed that the PowerShell console can be slow to open across various computers, sometimes taking several minutes. This slow start impacts not only the command shell (powershell.exe or pwsh.exe) but also the execution of logon PowerShell scripts via Group Policy Objects (GPO) or scheduled tasks. In this piece, we will explore possible causes [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":11041,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[],"class_list":["post-11040","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/11040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/comments?post=11040"}],"version-history":[{"count":0,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/11040\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media\/11041"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=11040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=11040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=11040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}