启动PowerShell会话时出错

时间:2015-04-08 15:29:21

标签: windows powershell powershell-v4.0

我正常使用PowerShell(仅使用posh git),突然发生了一个奇怪的行为,我试图重启会话,当我这样做时,我遇到了很多错误,是:

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

这是一张照片:

enter image description here

我尝试重新启动PC,但每次启动新的PowerShell会话时仍然遇到同样的问题,我注意到很多命令都不起作用,导致这个问题的原因是什么?我该怎么做才能解决它?

更新

我删除了PoshGit添加的配置文件,在开始新会话时,我没有任何错误,但是PowerShell仍然无法识别命令,例如调用Clear-host,会抛出很多我无法解决的错误了解原因!

enter image description here

3 个答案:

答案 0 :(得分:4)

您的PSModulePath系统环境变量缺失C:\windows\system32\WindowsPowerShell\v1.0\Modules,这是PowerShell中所有" system" /内置模块的位置。

你安装过的东西(可能是他的git?)可能搞砸了。将其添加到系统变量中。

没有PowerShell的最简单方法是使用如下所述的GUI: http://www.computerhope.com/issues/ch000549.htm

答案 1 :(得分:0)

如果您刚刚安装了posh-git,它会添加一些Powershell profile files,基本上每次执行PowerShell会话时都会执行一些.ps1文件。

只需删除(或修复)它们;从投掷错误的路径可能它们在C:\Users\aymen.daoudi\Documents\WindowsPowerShell\...

答案 2 :(得分:0)

在安装posh-git ... profile.example.ps1 is not recognized as the name of a cmdlet后加载我的个人资料时,我遇到类似的shell错误消息。

当我从旧机器上复制文件到我的用户目录时,发生了这种情况 - 较旧的 poshgit powershell user profiles came along with it

我的修复方法是从下面的路径重命名旧的posh-git个人资料...

原始档案路径

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

新的个人资料名称

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

choco uninstall poshgitchoco install poshgit之后,使用正确的数据创建了新的配置文件(大小从5KB增加到1KB )。