windows - 启动 PowerShell session 时出错

标签 windows powershell powershell-4.0

我正常使用 PowerShell(正在使用 posh git,只是提一下),突然发生了一个奇怪的行为,我试图重新启动 session ,当我这样做时,我得到了很多错误,它们是:

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 session 时仍然出现同样的问题,我注意到很多命令都不起作用,是什么导致了这个问题?我应该怎么做才能解决它?

更新

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

enter image description here

最佳答案

你是 PSModulePath 系统环境变量丢失 C:\windows\system32\WindowsPowerShell\v1.0\Modules 这是所有“系统”/PowerShell 中的内置模块。

你安装的东西(也许是 posh git?)可能把它搞砸了。将其添加到系统变量中。

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

关于windows - 启动 PowerShell session 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29518969/

相关文章:

java - 执行set命令时不显示环境变量

powershell - unescape unicode字符串powershell

python - 确定 Powershell 脚本是否在主范围内启动?

windows - PowerShell:(ConvertTo-* | Set-Content) 和 (Export-*) 之间的区别?

C++:如何使用谷歌测试在单元测试中模拟不同的时区

php - cronjob/trigger 可以每天更新数据库

c++ - 屏幕像素测试不符合预期 (win32 c++)

powershell - 为什么我不能从 WMI 中选择 AliasProperty?

filter - 搜索属性为空的用户

c# - 在使用 Powershell Api 时,有什么方法可以在 C# 中将 PSObject 转换为字符串