10
votes

I am having a difficult time installing/updating my powershell modules. I noticed this when I tried installing DBA Tools moudle. Reference links are https://dbatools.io/download/ and https://github.com/sqlcollaborative/dbatools.

It's a corporate PC. But I know that I have installed other modules before in the past. Does anyone have any idea what's going on?


PS (Admin)>

Install-Module DBATools

  • NOTE: The Install-Module command pauses for many minutes before the command returns a warning message.

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'. ERROR: "PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'PowerShellGet'".

Update-Module PowerShellGet

ERROR: "Update-Module : Module 'PowerShellGet' was not installed by using Install-Module, so it cannot be updated.".

Update-Module PowerShellGet -Force

ERROR: "Update-Module : Module 'PowerShellGet' was not installed by using Install-Module, so it cannot be updated.".

Find-Module dbatools

  • NOTE: The Find-Module command pauses for many minutes before the command returns an error message.

ERROR: "No match was found for the specified search criteria and module name 'dbatools'. Try Get-PSRepository to see all available registered module repositories."

Get-PSRepository | fl *

Name : PSGallery

SourceLocation : https://www.powershellgallery.com/api/v2

Trusted : False

Registered : True

InstallationPolicy : Untrusted

PackageManagementProvider : NuGet

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

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

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

ProviderOptions : {}

Get-Module PackageManagement -ListAvailable

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version Name ExportedCommands

Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...

Binary 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}}
     }

 }         

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'. WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'. WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'. WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'. WARNING: Unable to resolve package source '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

WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.

PackageManagement\Find-Package : No match was found for the specified search criteria and module name 'dbatools'. Try Get-PSRepository to see all available registered module repositories.

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

Invoke-WebRequest : The underlying connection was closed: The connection was closed unexpectedly.


Some references I tried

windows 10 - Powershell won't install almost any module using install-module - Stack Overflow Powershell won't install almost any module using install-module

There's a script for that: Install-Module - unable to resolve package source 'https //www.powershellgallery.com/api/v2/' https://vanbrenk.blogspot.com/2017/09/install-module-unable-to-resolve.html

Update Manually Installed PowerShell Modules from the PowerShell Gallery – Mike F Robbins https://mikefrobbins.com/2016/06/09/update-manually-installed-powershell-modules-from-the-powershell-gallery/

Update-Module : Module 'PowershellGet' was not installed by using Install-Module, so it cannot be updated. - Evotec https://evotec.xyz/update-module-module-powershellget-was-not-installed-by-using-install-module-so-it-cannot-be-updated/

5
Does Find-Module dbatools work?Mathias R. Jessen
If this is a home system, this would be surprising. If this is a corporate/enterprise-managed machine, then they could be blocking you. I've seen blocking this in several customer environments.postanote
It's a corporate PC. I've been using PS for a couple years at my corporation, and I have installed other modules before. What else can I check to get this resolved?SherlockSpreadsheets
Do you get a valid response if you just send an HTTP request to the gallery directly? ie. Invoke-WebRequest https://www.powershellgallery.com/api/v2Mathias R. Jessen
It could be a TLS issue. Try forcing TLS1.2 by running the following command first: [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12JonPayne

5 Answers

14
votes

I ran into the same error installing different module. My fix was specifying TLS1.2 for the .net Security protocol.

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

9
votes

Try running Register-PSRepository -Default

4
votes

Thanks to Stephen, rouxquasar it worked with below order for me Windows 2016 Datacenter, KB4598243, Execution policy was set properly so didn't have to deal with that.

  1. Enable TLS 1.2

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

  2. Register default PS Gallery Repo (may check Get-PSRepository | fl* just incase)

    Register-PSRepository -Default

  3. Install-Module dbatools (check Find-Module before to validate)

Use -Force switch if an older version of dbatools exists

1
votes

I have tried register-psrepository and it executed with out any error but after when I try get-psrepository its was still giving same error message "WARNING: Unable to find module repositories.", I tried different option below steps worked for me:

  1. register ps repository with a different name and use the same psgallery api for source location. Register-PSRepository PSGallery1 -SourceLocation "https://www.powershellgallery.com/api/v2" -InstallationPolicy Trusted

  2. set the repository Set-PSRepository PSGallery1

  3. now when I check the repository it worked like charm PSGAllery1 is the Name I have used

0
votes

Enabled Group Policy to allow scripts and set execution policy to bypass. I am now able to install the module. However, I must run the install with Scope current user and am still unable to install with As Admin powershell.

Module Install

Install-Module DBATools -Scope CurrentUser

Group Policy (Fix)

#*****************
FIX ...
#*****************

## PS (As Admin)
gpedit.msc
# Navigate to: Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell. Change the “Turn on Script Execution”
# Turn on Script Execution > Enabled, Policy "Allow all scripts"

## PS (As Admin)
Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass


<# 
#*****************
REFERENCE ...
#*****************
 Windows PowerShell - the setting is overridden by a policy defined at a more specific scope
 https://vladtalkstech.com/2015/03/windows-powershell-updated-execution-policy-successfully-setting-overridden-policy-defined-specific-scope.html

 Change the PowerShell MachinePolicy Execution Policy in WS 2012R2
 https://vladtalkstech.com/2014/03/change-powershell-machinepolicy-execution-policy-windows-server-2012r2.html
#>


#*****************
CAUSE ...
#*****************

Get-ExecutionPolicy –List

Set-ExecutionPolicy -Scope MachinePolicy Unrestricted

## However, you might have an error saying it can only be done via Group Policy.
## “Set-ExecutionPolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes mustbe set through Group Policy