Powershell very slow to open/respond

11

10

I am having an issue running PowerShell 3.0 on Windows 7 64-bit. It takes a very long time to open/start when run it. It is also quite sluggish in response to just about anything.

I believe this may be due to the fact that my profile is stored in my documents, and the my documents folder is synched to our network.

Is there any way that I can move the location of my profile so that I can have it local instead of over the network?

czuroski

Posted 2013-04-04T19:02:35.370

Reputation: 359

1its slow for me too and my profile is on direct drive access. also it is read once, cached by OS and closed after startup so network or not it should affect nothing. this is just MS poor attempt at redoing the wheel, but square, yet again. – v.oddou – 2013-11-26T01:13:28.770

Answers

17

PowerShell relies on the .NET Framework, you can try updating that.

This script also helped my speed

$Env:PATH = [Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
[AppDomain]::CurrentDomain.GetAssemblies() | % {
  $pt = $_.Location
  if (! $pt) {continue}
  if ($cn++) {''}
  $na = Split-Path -Leaf $pt
  Write-Host -ForegroundColor Yellow "NGENing $na"
  ngen install $pt
}

Steven Penny

Posted 2013-04-04T19:02:35.370

Reputation: 7 294

1Thank you! What a big difference after I ran this script. – WeSam Abdallah – 2015-07-13T16:09:21.173

3What does it do? – Pureferret – 2016-06-10T18:40:58.087

2ngen.exe install: Generate native images for an assembly and its dependencies and install them in the Native Images Cache. If /queue is specified compilation job is queued up. If a priority is not specified, the default priority used is 3. – VertigoRay – 2016-10-23T21:03:38.943

I am … surprised and impressed :-) – Chris F Carroll – 2018-05-18T17:00:06.487

1

The above answer that talks about NGEN reduced my startup time from over 30 seconds, to under 5.

However I have also seen cases where hitting Ctrl-C after waiting a few seconds gets me to a prompt, and I already did the NGEN trick above, and in that case, I suspect it's my scripts that are slowing me down.

If it's over 30 seconds, and you already tried the NGEN trick above, the most common reason is that your personal and system profile powershell scripts are taking a long time to start. If you're complaining about a delay less than 10 seconds, then it's probably .net which is slow to start.

If you're on a VM and the VM host is totally hogtied and IO-bound like most over-provisioned and under-resourced VM environments are, then it's that.

Warren P

Posted 2013-04-04T19:02:35.370

Reputation: 2 623

0

There are a few different default places the Powershell profile can be stored.

  • The first location is the global location and would be useful when you want all users to have a customized Powershell profile. This profile should be placed in

    C:\WINDOWS\system32\WindowsPowerShell\v1.0\Profile.ps1
    
  • The second location is for the local profile and would be specific to each user account. This file overrides the global configuration file and should be placed in

    C:\Username\My Documents\WindowsPowerShell\Profile.ps1
    

As a test try modifying the global Powershell profile (located in system32) and see if that speeds things up. If it does you will know the slowness is somehow due to the network and you can move forward from there.

jmreicha

Posted 2013-04-04T19:02:35.370

Reputation: 1 671

0

Recently, I had a similar issue when developing a binary PowerShell module. My console was extremely slow in response to almost anything. Steven Penny's script worked for me, but only per instance of PowerShell. I did not really understand what was going on in his script; so I went line by line to see where my problem was.

It ended up being with my path environmental variable. I had UNC path string in my path variable, and the delay was caused, because PowerShell will open/close the connection for each execution (i.e. every time you press the enter key).

Aaron Ray

Posted 2013-04-04T19:02:35.370

Reputation: 101

2What's UNC? How did you fix it? – Tomáš Zato - Reinstate Monica – 2015-08-22T19:27:16.943

1@TomášZato - Universal Naming Convention (UNC) is a path which contains forward or backward slashes. I understand this comment is 4 years late, figured you would want to know, since nobody ever bothered answering your question. I would assume the author removed the UNC path from their system variable. – Ramhound – 2019-10-02T14:40:38.093

@Ramhound Thanks! – Tomáš Zato - Reinstate Monica – 2019-10-02T14:49:07.707