1

I was using PowerShell normally (was using posh git, just to mention), and suddenly a weird behavior happened, I tried to restart the session, when I did, I got many errors, which are :

Split-Path : The term 'Split-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\aymen.daoudi\Documents\WindowsPowerShell\Modules\posh-git\profile.example.ps1:1 char:16
+ Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -P ...
+                ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Split-Path:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Import-Module : The specified module '.\posh-git' was not loaded because no valid module file was found in any module directory.
At C:\Users\aymen.daoudi\Documents\WindowsPowerShell\Modules\posh-git\profile.example.ps1:4 char:1
+ Import-Module .\posh-git
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (.\posh-git:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Enable-GitColors : The term 'Enable-GitColors' 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\aymen.daoudi\Documents\WindowsPowerShell\Modules\posh-git\profile.example.ps1:26 char:1
+ Enable-GitColors
+ ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Enable-GitColors:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Pop-Location : The term 'Pop-Location' 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\aymen.daoudi\Documents\WindowsPowerShell\Modules\posh-git\profile.example.ps1:28 char:1
+ Pop-Location
+ ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Pop-Location:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Start-SshAgent : The term 'Start-SshAgent' 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\aymen.daoudi\Documents\WindowsPowerShell\Modules\posh-git\profile.example.ps1:30 char:1
+ Start-SshAgent -Quiet
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Start-SshAgent:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Here's a picture of that :

enter image description here

I tried to restart the PC, but still have the same problem every time I start a new PowerShell session, I noticed that many commands don't work, what caused this problem ? and what should I do to solve it ?

Update

I removed the profiles added by PoshGit, when starting a new session, I don't have any error, but powershell still doesn't recognize commands, for example calling Clear-host, throws lots of errors that I can't understand the cause !

enter image description here

5
  • What does $env:PSModulePath return? Does dir C:\windows\system32\WindowsPowerShell\v1.0\Modules return any modules (don't need the list, does it return many folders?)? Commented Apr 9, 2015 at 10:39
  • $env:PSModulePath returns 3 folders, dir C:\windows\system32\WindowsPowerShell\v1.0\Modules generates an error CommandNotFoundException saying `The term 'Get-ChildItem is not recognized as the name of a cmdlet, function, script file ...' Commented Apr 9, 2015 at 10:54
  • True. My bad. :) Can you browse the folder in Windows Explorer and see if the modules are there? Should be around 57 folders inside. Was C:\windows\system32\WindowsPowerShell\v1.0\Modules one of the paths in $env:PSModulePath? Commented Apr 9, 2015 at 11:32
  • @FrodeF. No, C:\windows\system32\WindowsPowerShell\v1.0\Modules is not one of the paths in $env:PSModulePath, but when I check it in File Explorer it contains 65 folders. Commented Apr 9, 2015 at 13:39
  • Good. Check out my answer. :) Commented Apr 10, 2015 at 8:02

3 Answers 3

4

You're PSModulePath system environment varaible is missing C:\windows\system32\WindowsPowerShell\v1.0\Modules which is the location of all "system"/built-in modules in PowerShell.

Something you've installed (posh git maybe?) has probably messed it up. Add it to the system variable.

The easiest way to do it without PowerShell is using the GUI as described here: http://www.computerhope.com/issues/ch000549.htm

Sign up to request clarification or add additional context in comments.

Comments

0

If you just installed posh-git it added some Powershell profile files, basically some .ps1 files executed each time a powershell session starts.

Just remove (or fix) them; from the path in the errors thrown probably they are in C:\Users\aymen.daoudi\Documents\WindowsPowerShell\...

2 Comments

I've been using PoshGit for a long time, this problem just happened suddenly, but I'm going to check anyway
basic cmdlets corrupted... no idea, sorry
0

I had a similar shell error message when loading my profile after installing posh-git ... profile.example.ps1 is not recognized as the name of a cmdlet.

This happened to me when I copied over files to my user directory from an older machine - the older poshgit powershell user profiles came along with it.

The fix for me was to rename the old posh-git profile from the path below...

Original Profile Path

C:\Users\<username>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

New Profile Name

C:\Users\<username>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1.notused

After choco uninstall poshgit and choco install poshgit a new profile was created with the right data (went from 5KB to 1KB in size).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.