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
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
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/
Installing PowerShell modules from the PowerShell Gallery is the easiest way to install modules. To install a package or module from the Gallery, we use the command: Install-Module or Install-Script cmdlet, depending on the package type.
Open an elevated Windows PowerShell command prompt (run Windows PowerShell as an administrator). Run the Install-Module MSOnline command. If you're prompted to install the NuGet provider, type Y and press Enter. If you're prompted to install the module from PSGallery, type Y and press Enter.
On the Features page, expand Remote Server Administration Tools > Role Administration Tools > AD DS and AD LDS Tools, then select Active Directory module for Windows Powershell. Once selected, click Next. On the Confirmation page, click Install. Once the install completes successfully, click Close.
Open PowerShell as administrator. Run the command Install-Module PowerShellGet -Force to install the NuGet package. When asked for confirmation to install the NuGet provider, press the Y key and press Enter .
Try running Register-PSRepository -Default
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
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.
Enable TLS 1.2
:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Register the default PS Gallery Repo (may check Get-PSRepository | fl*
just incase)
Register-PSRepository -Default
Install-Module dbatools
(check Find-Module
before to validate)
Use -Force
switch if an older version of dbatools
exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With