11

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?

  • 1
    its 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 Nov 26 '13 at 1:13
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
}
  • 1
    Thank you! What a big difference after I ran this script. – WeSam Abdallah Jul 13 '15 at 16:09
  • 3
    What does it do? – Pureferret Jun 10 '16 at 18:40
  • 2
    ngen.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 Oct 23 '16 at 21:03
  • I am … surprised and impressed :-) – Chris F Carroll May 18 '18 at 17:00
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.

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.

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).

  • 2
    What's UNC? How did you fix it? – Tomáš Zato Aug 22 '15 at 19:27
  • 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 Oct 2 at 14:40
  • @Ramhound Thanks! – Tomáš Zato Oct 2 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.