Powershell 安装 - 找不到指定搜索条件和模块名称的匹配项

She*_*ets 10 powershell windows-10

我在安装/更新我的 powershell 模块时遇到了困难。我在尝试安装 DBA Tools 模块时注意到了这一点。参考链接是https://dbatools.io/download/https://github.com/sqlcollaborative/dbatools

这是一台企业电脑。但我知道我以前安装过其他模块。有谁知道发生了什么?


PS(管理员)>

Install-Module DBATools

  • 注意:Install-Module 命令在返回警告消息之前会暂停几分钟。

警告:无法解析包源“https://www.powershellgallery.com/api/v2”。错误:“PackageManagement\Install-Package:未找到指定搜索条件和模块名称‘PowerShellGet’的匹配项”。

Update-Module PowerShellGet

错误:“更新模块:模块 'PowerShellGet' 未使用 Install-Module 安装,因此无法更新。”。

Update-Module PowerShellGet -Force

错误:“更新模块:模块 'PowerShellGet' 未使用 Install-Module 安装,因此无法更新。”。

Find-Module dbatools

  • 注意: Find-Module 命令在返回错误消息之前会暂停几分钟。

错误:“未找到与指定搜索条件和模块名称 'dbatools' 匹配的内容。尝试 Get-PSRepository 以查看所有可用的已注册模块存储库。”

Get-PSRepository | fl *

名称:PS画廊

来源位置:https ://www.powershellgallery.com/api/v2

信任:错误

注册 : 真

安装策略:不受信任

包管理提供程序:NuGet

发布位置:https ://www.powershellgallery.com/api/v2/package/

ScriptSourceLocation : https://www.powershellgallery.com/api/v2/items/psscript

ScriptPublishLocation : https://www.powershellgallery.com/api/v2/package/

提供者选项:{}

Get-Module PackageManagement -ListAvailable

目录:C:\Program Files\WindowsPowerShell\Modules

ModuleType 版本名称 ExportedCommands

二进制 1.0.0.1 PackageManagement {Find-Package、Get-Package、Get-PackageProvider、Get-Packa...

二进制 1.0.0.1 PackageManagement {Find-Package、Get-Package、Get-PackageProvider、Get-Packa...

Get-Module -ListAvailable |
 Where-Object ModuleBase -like $env:ProgramFiles\WindowsPowerShell\Modules\* |
 Sort-Object -Property Name, Version -Descending |
 Get-Unique -PipelineVariable Module |
 ForEach-Object {
     if (-not(Test-Path -Path "$($_.ModuleBase)\PSGetModuleInfo.xml")) {
         Find-Module -Name $_.Name -OutVariable Repo -ErrorAction SilentlyContinue |
         Compare-Object -ReferenceObject $_ -Property Name, Version |
         Where-Object SideIndicator -eq '=>' |
         Select-Object -Property Name,
                                 Version,
                                 @{label='Repository';expression={$Repo.Repository}},
                                 @{label='InstalledVersion';expression={$Module.Version}}
     }

 }         
Run Code Online (Sandbox Code Playgroud)

警告:无法解析包源“https://www.powershellgallery.com/api/v2”。警告:无法解析包源“https://www.powershellgallery.com/api/v2”。警告:无法解析包源“https://www.powershellgallery.com/api/v2”。警告:无法解析包源“https://www.powershellgallery.com/api/v2”。警告:无法解析包源“https://www.powershellgallery.com/api/v2”。

$webclient=New-Object System.Net.WebClient
$webclient.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[Net.ServicePointManager]::SecurityProtocol = "tls12"
Find-Module dbatools
Run Code Online (Sandbox Code Playgroud)

警告:无法解析包源“https://www.powershellgallery.com/api/v2”。

PackageManagement\Find-Package :未找到指定搜索条件和模块名称“dbatools”的匹配项。尝试 Get-PSRepository 以查看所有可用的已注册模块存储库。

Invoke-WebRequest https://www.powershellgallery.com/api/v2

Invoke-WebRequest : 底层连接已关闭:连接意外关闭。


我试过的一些参考资料

windows 10 - Powershell 不会使用 install-module 安装几乎任何模块 - 堆栈内存溢出 Powershell 不会使用 install-module 安装几乎任何模块

有一个脚本:安装模块 - 无法解析包源'https //www.powershellgallery.com/api/v2/' https://vanbrenk.blogspot.com/2017/09/install-module-unable- to-resolve.html

从 PowerShell 库更新手动安装的 PowerShell 模块 – Mike F Robbins https://mikefrobbins.com/2016/06/09/update-manually-installed-powershell-modules-from-the-powershell-gallery/

Update-Module :模块“PowershellGet”未使用 Install-Module 安装,因此无法更新。- Evotec https://evotec.xyz/update-module-module-powershellget-was-not-installed-by-using-install-module-so-it-cannot-be-updated/

Ste*_*hen 18

我在安装不同的模块时遇到了同样的错误。我的修复是为 .net 安全协议指定 TLS1.2。

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12


小智 9

尝试跑步 Register-PSRepository -Default

  • 这对我在带有 PSVersion 5.1.14393.2969 框的 Win 2016 标准上有效,但只有在我发出 @Stephen 的答案中提到的 TLS 配置设置之后 (2认同)

小智 8

重新注册 PS 默认存储库作为管理员为我修复:

  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  Unregister-PSRepository -Name PSGallery
  Register-PSRepository -Default
  Find-Module dbatools
Run Code Online (Sandbox Code Playgroud)


Vin*_*nay 5

感谢斯蒂芬,rouxquasar 它为我使用了以下顺序 Windows 2016 数据中心,KB4598243,执行策略设置正确,因此不必处理。

  1. 启用 TLS 1.2

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

  2. 注册默认的 PS Gallery Repo(可以检查 Get-PSRepository | fl* 以防万一)

    注册-PSRepository-默认

  3. Install-Module dbatools(在验证之前检查 Find-Module)

如果存在旧版本的 dbatools,请使用 -Force 开关


She*_*ets 0

启用组策略以允许脚本并设置执行策略以绕过。我现在可以安装该模块了。但是,我必须使用 Scope 当前用户运行安装,但仍然无法使用 As Admin powershell 进行安装。

\n

模块安装

\n
Install-Module DBATools -Scope CurrentUser\n
Run Code Online (Sandbox Code Playgroud)\n

组策略(修复)

\n
#*****************\nFIX ...\n#*****************\n\n## PS (As Admin)\ngpedit.msc\n# Navigate to: Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell. Change the \xe2\x80\x9cTurn on Script Execution\xe2\x80\x9d\n# Turn on Script Execution > Enabled, Policy "Allow all scripts"\n\n## PS (As Admin)\nSet-ItemProperty -Path HKLM:\\Software\\Policies\\Microsoft\\Windows\\PowerShell -Name ExecutionPolicy -Value ByPass\n\n\n<# \n#*****************\nREFERENCE ...\n#*****************\n Windows PowerShell - the setting is overridden by a policy defined at a more specific scope\n https://vladtalkstech.com/2015/03/windows-powershell-updated-execution-policy-successfully-setting-overridden-policy-defined-specific-scope.html\n\n Change the PowerShell MachinePolicy Execution Policy in WS 2012R2\n https://vladtalkstech.com/2014/03/change-powershell-machinepolicy-execution-policy-windows-server-2012r2.html\n#>\n\n\n#*****************\nCAUSE ...\n#*****************\n\nGet-ExecutionPolicy \xe2\x80\x93List\n\nSet-ExecutionPolicy -Scope MachinePolicy Unrestricted\n\n## However, you might have an error saying it can only be done via Group Policy.\n## \xe2\x80\x9cSet-ExecutionPolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes mustbe set through Group Policy\n
Run Code Online (Sandbox Code Playgroud)\n