安装 PowerShellGet 模块

Geo*_*ley 5 powershell

我正在使用 Windows 2012 R2,它运行的是 PowerShell 版本 4.0。我已经升级到5.0版本了。

\n\n

似乎当我执行基本命令时会出现错误,例如,

\n\n
PS C:\\Windows\\system32> Install-Module \xe2\x80\x93Name PowerShellGet \xe2\x80\x93Force \xe2\x80\x93Verbose\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n

Install-Module : 在模块\n“PowerShellGet\”中找到“Install-Module”命令,但无法加载该模块。有关详细信息,请运行“Import-Module PowerShellGet”。在行:1个字符:1\n + Install-Module \xe2\x80\x93Name PowerShellGet \xe2\x80\x93Force \xe2\x80\x93Verbose\n + ~~~~~~~~~~~~~~~\ n + CategoryInfo:ObjectNotFound:(安装模块:字符串)[],CommandNotFoundException\n + ExcellentQualifiedErrorId:CouldNotAutoloadMatchingModule

\n
\n\n

另一个例子:

\n\n
PS C:\\Windows\\system32> import-module PowerShellGet\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n

Get-Variable :术语“Get-Variable”不被识别为 cmdlet、函数、脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。在 C:\\Program\n Files\\WindowsPowerShell\\Modules\\PowerShellGet\\1.1.3.2\\PSModule.psm1:18\n char:28\n + $script:IsWindows = (-not (Get-Variable -Name IsWindows -ErrorAction ...\n + ~~~~~~~~~~~~\n + CategoryInfo : ObjectNotFound: (Get-Variable:String) [], CommandNotFoundException\n + ExcellentQualifiedErrorId : CommandNotFoundException

\n
\n\n

我基本上遵循此处找到的 PowerShellGet 安装方法:https://learn.microsoft.com/en-us/powershell/gallery/psget/get_psget_module

\n\n

我被本指南中的“Install-Module”命令困住了。

\n

Caf*_*der 7

在执行 install-module 之前,在 powershell 上执行命令:“Set-ExecutionPolicy Unrestricted”。(限制模式可以帮助您防止未经授权的脚本)