【问题标题】:PowerShell load module with specific version特定版本的 PowerShell 加载模块
【发布时间】:2020-12-31 12:11:38
【问题描述】:

我正在尝试在 Windows 10 中通过 Powershell 安装公司工具,它需要 PowerShell 版本 7.0+,但是当我尝试调用我们的公司工具时,我的 Windows 中似乎有两个版本的 PowerShell,我收到了这个错误:

The 'Tool-Name' command was found in the module 'PCP.AWS', but the module could not be loaded. For more information, run 'Import-Module PCP.AWS'.

然后我运行命令“Import-Module PCP.AWS”,但出现此错误:

Import-Module : The version of Windows PowerShell on this computer is '5.1.18362.145'. The module 'C:\Program Files
(x86)\WindowsPowerShell\Modules\PCP.AWS\0.0.23\PCP.AWS.psd1' requires a minimum Windows PowerShell version of '7.0' to run. Verify that you have the minimum required version of Windows PowerShell installed, and then try again.

这是我运行 pwsh -V PowerShell 7.1.0 时的输出,但如果我运行 Get-Host | Select-Object Version 我也可以得到一个输出

Version
-------
5.1.18362.145

谁能建议我应该怎么做才能让这个工具可以运行?我应该通过特定的 PowerShell 版本来运行这个工具,还是应该在我的笔记本电脑中删除旧版本的 PowerShell?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    问题可能是您运行的是 Windows PowerShell 版本 5.1.x。当您运行pwsh -v 时,实际上是从 5.1 shell 调用 PowerShell 核心可执行文件,并将其输出 (PowerShell 7.1.0) 返回到 5.1 shell 并立即退出。这就是为什么当你运行 $host 时你会得到 5.1.x

    因此,您显然已将 7.1 与 Windows PowerShell 并排安装。转到开始运行类型 pwsh 并按回车键。现在您将进入 7.1 shell,继续加载模块。

    注意:您还可以通过从开始菜单搜索找到 PowerShell Core。它可能被标记为“PowerShell 7 (x64)。可执行文件位于“C:\Program Files\PowerShell\7\pwsh.exe”

    最后一点:在 Shell 中检查 PowerShell 版本的最佳方法是通过 $PSVersiontTable 自动变量。输出将如下所示:

    Name                           Value
    ----                           -----
    PSVersion                      5.1.14409.1018
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14409.1018}
    BuildVersion                   10.0.14409.1018
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    

    PwSh 7.1 中的输出略有不同:

    Name                           Value
    ----                           -----
    PSVersion                      7.1.0
    PSEdition                      Core
    GitCommitId                    7.1.0
    OS                             Microsoft Windows 6.3.9600
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0.}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    

    如果你需要 7.1 版本,你有它,然后使用它......

    【讨论】:

    • 为我工作!非常感谢!
    猜你喜欢
    • 2016-03-29
    • 1970-01-01
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-04
    • 2015-09-14
    • 2017-09-26
    相关资源
    最近更新 更多