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

标签 powershell windows-10

我很难安装/更新我的 powershell 模块。我在尝试安装 DBA Tools moudle 时注意到了这一点。引用链接是 https://dbatools.io/download/https://github.com/sqlcollaborative/dbatools .
这是一台公司PC。但我知道我以前安装过其他模块。有谁知道发生了什么?

PS(管理员)> Install-Module DBATools

  • 注意: Install-Module 命令会暂停几分钟,然后该命令会返回警告消息。

  • 警告:无法解析包源“https://www.powershellgallery.com/api/v2”。
    错误:“PackageManagement\Install-Package:未找到指定搜索条件和模块名称‘PowerShellGet’的匹配项”。Update-Module PowerShellGet错误:“更新模块:模块 'PowerShellGet' 未使用安装模块安装,因此无法更新。”。Update-Module PowerShellGet -Force错误:“更新模块:模块 'PowerShellGet' 未使用安装模块安装,因此无法更新。”。Find-Module dbatools
  • 注意:Find-Module 命令会在命令返回错误消息之前暂停数分钟。

  • 错误:“未找到指定搜索条件和模块名称‘dbatools’的匹配项。尝试 Get-PSRepository 以查看所有可用的已注册模块存储库。”Get-PSRepository | fl * 名称:PSGallery
    来源位置:https://www.powershellgallery.com/api/v2
    可信:错误
    已注册:真
    InstallationPolicy:不受信任
    包管理提供者:NuGet
    发布位置:https://www.powershellgallery.com/api/v2/package/
    脚本来源位置:https://www.powershellgallery.com/api/v2/items/psscript
    脚本发布位置: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}}
         }
    
     }         
    
    警告:无法解析包源“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
    
    警告:无法解析包源“https://www.powershellgallery.com/api/v2”。
    PackageManagement\Find-Package :未找到指定搜索条件和模块名称“dbatools”的匹配项。尝试
    Get-PSRepository 以查看所有可用的已注册模块存储库。Invoke-WebRequest https://www.powershellgallery.com/api/v2Invoke-WebRequest :底层连接已关闭:连接意外关闭。

    我试过的一些引用资料
    windows 10 - Powershell几乎不会使用install-module安装任何模块 - Thinbug
    Powershell won't install almost any module using 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/

    最佳答案

    我在安装不同的模块时遇到了同样的错误。我的解决方法是为 .net 安全协议(protocol)指定 TLS1.2。
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    关于Powershell 安装 - 未找到指定搜索条件和模块名称的匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63385304/

    相关文章:

    powershell - 构建完成后,TFS 2015 不再将内部版本号添加到全局列表中?

    powershell - 重命名项目 : Source and destination path must be different error in Powershell

    c# - 通过代码C# UWP旋转位图

    c# - Winform 应用程序名称在 Windows 10 任务管理器的“启动”选项卡上显示为 _alphanumeric

    c# - 在 Windows 10 通用应用程序中播放音频和视频?

    c++ - 在 Windows 10 通用应用程序 UWP 上覆盖关闭框

    powershell - 订单项目 : A, B、AA、AB

    Powershell 根据 CSV 中的唯一列 ID 删除重复条目

    数组理解中的 PowerShell 函数

    maven - Jenkins Pipeline-无法连接到Docker守护程序