在Windows Server 2008 r2 sp1机器上,我使用chocolatey来安装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
可能只是在开始时缺少一些设置环境的脚本执行。如果你比我更了解并且可以提供一些帮助并且可以做到这一点我不需要重建这台机器,我会非常高兴。
答案 0 :(得分:10)
游戏有点晚了,但最近遇到了这个问题。我发现我的PSModulePath没有包含重要路径。您可以通过运行以下命令来查看PSModulePath:
$ ENV:PSModulePath
要添加所需的路径,您可以运行此命令:
$ env:PSModulePath = $ env:PSModulePath +“; C:\ Windows \ system32 \ WindowsPowerShell \ v1.0 \ Modules \”
答案 1 :(得分:3)
这是一个非常古老的主题,但是因为我在解决完全相同的问题时发现它 - 我想我会提到我是如何解决它的。
首先是我遇到的问题:
我在Windows 7上安装了PowerShell 2.0,然后使用choco安装/升级到PowerShell 4.0:
choco upgrade powershell
将我的系统更新为4.0,但是当我打开PowerShell时,升级打破了大多数基本cmdlet,例如Get-ChildItem(aka dir)。
在网上摸索了一段时间之后,我想我会从MS网站重新安装......但首先我从choco中卸载了。
choco uninstall powershell
因为choco一开始就打破了它,我以为我会再尝试使用以下命令干净地安装它:
choco install powershell --force
低,这解决了问题。 所以我就在那里停下来 希望这对某人有帮助。 祝你好运!