2

My PowerShell shell sometimes hangs after any command - such as ls. Also, after I force close the window, when I open another shell window, it shows the following error:

Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.

Test-Path : The term 'Test-Path' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.
At C:\Users\user\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:9 char:5
+ if (Test-Path $PoshHistoryPath)
+     ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Test-Path:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

With -NoProfile option, this does not happen so I suspect something in my profile causes this, but it is hard to pinpoint what is the problem since usually after a while PowerShell acts normally.

joon
  • 589
  • Try commenting out half of your profile. If you still have the problem, comment out half again of the remainder, and so on. Or uncomment half if the problem does go away. That is, do a binary search. You should be able to find the cause of the problem pretty quickly. – dangph Jan 13 '14 at 01:23
  • Another thing to try might be to run Process Monitor from SysInternals with a filter of "process name contains powershell". When powershell hangs, you can look in Process Monitor to see what it was doing. If you are lucky, that might provide a clue. – dangph Jan 13 '14 at 01:28
  • Thanks for the comment. Again it got fixed automatically after a while. I will definitely check the process. – joon Jan 13 '14 at 02:23
  • is this different from the 2-3 second lag that occurs on first use after a reboot or after clearing standby cache when powershell is loading all it's Global assemblies. – Knuckle-Dragger Jan 15 '14 at 16:19
  • It is. It hangs indefinitely after any running cmdlet. I made some progress pinpointing where it happens - I will report it when I am sure. – joon Jan 15 '14 at 20:35
  • Turns out the culprit was posh-git. I need to dig deeper to see which part of my profile related to posh-git (or posh-git itself) is causing the problem. – joon Jan 27 '14 at 20:13
  • I have an extremely similar problem with Test-Path not being recognised a valid command sometimes, posted on http://stackoverflow.com/questions/22188829/powershell-test-path-is-not-recognized-as-a-cmdlet – BeowulfNode42 Jul 11 '14 at 04:56

1 Answers1

3

Turns out the culprit was outdated version of posh-git. Once I merged upstream commits the problem went away.

joon
  • 589
  • I have this same issue, apparently with posh-hg, but I have the latest version. I've looked through the commit history on posh-git, and I don't see commit that looks particularly relevant. Did the fix work for you ultimately? Do you recall what the outdated version of posh-git you had? One thing I've observed is that disabling the profile, starting powershell, then re-enabling the profile seems to work around the issue, but only for some time (days). – Jason R. Coombs Nov 30 '14 at 14:23
  • Yes I haven't had any problems since then. I do not recall the version of posh-git I had - I'm sorry. – joon Dec 01 '14 at 02:14
  • I think it was this commit: https://github.com/dahlbyk/posh-git/commit/02a3d8809f4b379e3a68d667248e620dbdb0c98a; And indeed some of the lines changed in that commit still exist in posh-hg. – Jason R. Coombs Dec 03 '14 at 14:49
  • 1
    The latest tip of posh-hg now also has the supposed fix. – Jason R. Coombs Feb 09 '15 at 13:16