7

在 windows server 2008 r2 sp1 机器上,我使用巧克力来安装AWSTools.Powershell包。这反过来又安装了 powershell 3。现在,powershell 已经彻底坏了,我想不出任何修复它或卸载并重新安装它的方法。

我担心我唯一的答案是完全重建机器,但想问是否有办法修复它。

powershell 实际运行,只是似乎找不到任何内置 cmdlet。似乎它确实找到了别名,但无法执行它们下面的内容。例如,发出 ls 来查看目录内容会产生:

PS C:\Users\Administrator> ls
ls : The term 'Get-ChildItem' 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 line:1 char:1
+ ls
+ ~~
    + CategoryInfo          : ObjectNotFound: (Get-ChildItem:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

可能只是在开始时缺少一些脚本的执行来设置环境。如果您比我了解更多并且可以提供一些帮助并且可以使我不必重建这台机器,我会很高兴。

4

2 回答 2

10

游戏有点晚了,但最近遇到了这个问题。我发现我的 PSModulePath 没有包含重要路径。您可以通过运行以下命令查看您的 PSModulePath:

$env:PSModulePath

要添加所需的路径,您可以运行以下命令:

$env:PSModulePath = $env:PSModulePath + ";C:\Windows\system32\WindowsPowerShell\v1.0\Modules\"

于 2014-08-20T17:13:14.717 回答
3

这是一个非常古老的线程,但是因为我在解决完全相同的问题时发现了它 - 我想我会提到我是如何解决它的。

首先是我遇到的问题:

我在 Windows 7 上安装了 PowerShell 2.0,然后使用 choco 安装/升级到 PowerShell 4.0:

choco upgrade powershell

这将我的系统更新到 4.0,但是当我打开 PowerShell 时,升级破坏了大多数基本 cmdlet,例如 Get-ChildItem(又名 dir)。

在网上摸索了一段时间后,我以为我会从 MS 网站重新安装......但首先我从 choco 卸载了。

choco uninstall powershell

由于是 choco 一开始就把它弄坏了,我想我会再试一次,用以下命令干净地安装它:

choco install powershell --force

低,这解决了问题。所以我停在那里。希望这对某人有帮助。祝你好运!

于 2015-08-02T21:59:54.560 回答