PowerShell Slow to Load and AutoFill

I had this problem on a server for a while – when first launching PowerShell, it would take ~20 seconds or so to accept input. Also, when pressing tab to auto-complete a command, it would again take ~20 seconds to start, like it was freezing. These were one time problems when launching PowerShell, after that it would work fine until a new session was launched.

A lot of searching didn’t help me work it out, so I logged a Microsoft case. After a few task manager executable dumps, they worked out the delay was on a path I had in an environment variable. Somehow in my account’s user variable, I had a github desktop path that was mapping to a network share, using a PC name that was decommissioned (e.g. ;\\pcname\c$\Users\AdamFowler\AppData\Local\GitHubDesktop\bin.

I expect that this name was timing out, and PowerShell was waiting a while before giving up. In case you have the same symptoms as me, check the environment variables – user variables paths if it’s only your account affected, or the system variables if it’s all users. Click on the path value, then click edit, and remove anything that shoudn’t be there (take a backup of the text if you aren’t sure, it’s easy to put back in if you keep a copy).

To get to Environment Variables, depending on the OS version, get to System Properties, the Advanced tab, and then the Environment Variables button:

Hope that helps someone else with the same problem!

2 thoughts on “PowerShell Slow to Load and AutoFill

    1. Actually, I needed a bit more diagnosis to solve this. I was able to construct the following script to expose the paths that were causing the issue:

      $times = [System.Collections.Generic.Dictionary[string,System.ValueType]]::new( ($env:Path -split ‘;’).Count )
      New-Variable -Name semaphore -Value ([System.Threading.Semaphore]::new(0,1,’times’)) -Option AllScope -Visibility Public -Scope Global
      $env:Path -split ‘;’ | ForEach-Object -Parallel { $time = Measure-Command -Expression { Get-ChildItem -Path $_ -Recurse }; $_sem = $using:semaphore; $_sem.WaitOne(); $_times = $using:times; $_times.Add( $_, $time ); $_sem.Release(); } -ThrottleLimit $env:NUMBER_OF_PROCESSORS

      I am not really sure if the semaphore was necessary. I don’t quite understand how parallel for-loops synchronize data in the new PowerShell, so I thought might as well be explicit.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.