启动 PowerShell 会话时出错
Errors when starting a PowerShell session
我正常使用 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
这是一张照片:
我尝试重新启动 PC,但每次启动新的 PowerShell 会话时仍然出现同样的问题,我注意到很多命令都不起作用,是什么导致了这个问题?我应该怎么做才能解决它?
更新
我删除了 PoshGit 添加的配置文件,当开始一个新的会话时,我没有任何错误,但是 powershell 仍然不能识别命令,例如调用 Clear-host,抛出很多错误,我可以不明白原因!
如果你刚刚安装了 posh-git 它添加了一些 Powershell profile files,基本上是一些 .ps1 文件在每次 powershell 会话启动时执行。
只需删除(或修复)它们;从抛出错误的路径来看,它们可能在 C:\Users\aymen.daoudi\Documents\WindowsPowerShell\...
您 PSModulePath
缺少系统环境变量 C:\windows\system32\WindowsPowerShell\v1.0\Modules
,它是 PowerShell 中所有 "system"/内置模块的位置。
您安装的某些东西(也许 git 很漂亮?)可能把它搞砸了。添加到系统变量中。
不使用 PowerShell 的最简单方法是使用 GUI,如下所述:
http://www.computerhope.com/issues/ch000549.htm
我在安装 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 poshgit
和 choco install poshgit
之后,使用正确的数据创建了一个新的配置文件(大小从 5KB 变为 1KB)。
我正常使用 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
这是一张照片:
我尝试重新启动 PC,但每次启动新的 PowerShell 会话时仍然出现同样的问题,我注意到很多命令都不起作用,是什么导致了这个问题?我应该怎么做才能解决它?
更新
我删除了 PoshGit 添加的配置文件,当开始一个新的会话时,我没有任何错误,但是 powershell 仍然不能识别命令,例如调用 Clear-host,抛出很多错误,我可以不明白原因!
如果你刚刚安装了 posh-git 它添加了一些 Powershell profile files,基本上是一些 .ps1 文件在每次 powershell 会话启动时执行。
只需删除(或修复)它们;从抛出错误的路径来看,它们可能在 C:\Users\aymen.daoudi\Documents\WindowsPowerShell\...
您 PSModulePath
缺少系统环境变量 C:\windows\system32\WindowsPowerShell\v1.0\Modules
,它是 PowerShell 中所有 "system"/内置模块的位置。
您安装的某些东西(也许 git 很漂亮?)可能把它搞砸了。添加到系统变量中。
不使用 PowerShell 的最简单方法是使用 GUI,如下所述: http://www.computerhope.com/issues/ch000549.htm
我在安装 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 poshgit
和 choco install poshgit
之后,使用正确的数据创建了一个新的配置文件(大小从 5KB 变为 1KB)。