Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

PowerShell load module with specific version

I am trying to install a company tool by Powershell in Windows 10, it requires PowerShell version 7.0+, but it looks like I have two versions of PowerShell in my Windows when I try to call our company tool I got this error:

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'.

Then I run the command 'Import-Module PCP.AWS' but I got this error:

Import-Module : The version of Windows PowerShell on this computer is '5.1.18362.145'. The module 'C:Program Files
(x86)WindowsPowerShellModulesPCP.AWS.0.23PCP.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.

Here's the output when I run pwsh -V PowerShell 7.1.0, but if I run Get-Host | Select-Object Version I can also get an output

Version
-------
5.1.18362.145

Can anyone suggest what should I do to get this tool runnable? Should I run this tool by specific PowerShell version or should I just remove the older version PowerShell in my laptop?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem may be you're running Windows PowerShell version 5.1.x. When you run pwsh -v, you are actually invoking the PowerShell core executable from the 5.1 shell and it's returning its output (PowerShell 7.1.0) to the 5.1 shell and promptly exiting. That's why when you run $host you are getting 5.1.x

As such you obviously have 7.1 installed side by side with Windows PowerShell. Go to start Run type pwsh and hit enter. Now you'll be in a 7.1 shell, go ahead and load the module.

Note: you can also find PowerShell Core by searching from the start menu. It may be labeled "PowerShell 7 (x64). The executable is located at "C:Program FilesPowerShell7pwsh.exe"

Last note: The best way to check the PowerShell version in your Shell is via the $PSVersiontTable automatic variable. The output will look like below:

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

The output is a little different in 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

If you need version 7.1, you have it, then use it...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...