Keywords: PowerShell | Module Installation | Group Policy | TLS 1.2 | Execution Policy
Abstract: This article provides an in-depth exploration of the common error "No match was found for the specified search criteria and module name" encountered when installing PowerShell modules in enterprise environments. By analyzing user-provided Q&A data, particularly the best answer (score 10.0), the article systematically explains the multiple causes of this error, including Group Policy restrictions, TLS protocol configuration, module repository registration issues, and execution policy settings. Detailed solutions are provided, such as enabling TLS 1.2, re-registering the default PSGallery repository, adjusting execution policy scopes, and using CurrentUser installation mode. Through reorganized logical structure and supplementary technical background, this article offers practical troubleshooting guidance for system administrators and PowerShell developers.
Problem Background and Error Manifestation
When installing or updating PowerShell modules in enterprise environments, users frequently encounter the error "No match was found for the specified search criteria and module name." This error is often accompanied by prolonged command pauses and warnings about unresolved package sources. Taking the installation of the dbatools module as an example, when users execute the Install-Module DBATools command, the system returns the following error:
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'".
Even attempts to update the PowerShellGet module result in the error "Module 'PowerShellGet' was not installed by using Install-Module, so it cannot be updated." Checking with the Get-PSRepository command shows that although the PSGallery repository is registered, connection issues persist.
Core Problem Analysis
Based on the analysis of Q&A data, this error is primarily caused by the following four factors:
Group Policy Execution Restrictions
In enterprise environments, Group Policy often restricts PowerShell script execution permissions. When execution policies at the MachinePolicy or UserPolicy scopes are set to restricted modes, module installation commands fail even when running PowerShell as an administrator. The Get-ExecutionPolicy –List command can display execution policy settings across scopes. If MachinePolicy is set to Restricted, adjustments must be made through the Group Policy Editor.
TLS Protocol Configuration Issues
The PowerShell Gallery requires TLS 1.2 protocol for secure connections. Older Windows versions or improperly configured systems may default to incompatible protocol versions. Setting [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 forces the use of TLS 1.2, resolving connection problems.
Module Repository Registration Status
Although Get-PSRepository indicates PSGallery is registered, the repository configuration may be incomplete or corrupted. Executing the Register-PSRepository -Default command re-registers the default PowerShell Gallery repository, ensuring correct source locations and installation policies.
Installation Scope Limitations
When system-level installation is blocked by Group Policy, using the -Scope CurrentUser parameter allows module installation within the user scope. This approach does not require administrator privileges but makes modules available only to the current user.
Comprehensive Solution
Based on the best answer (Answer 4) and other supplementary answers, the following resolution steps are recommended:
Step 1: Adjust Group Policy Settings
Run gpedit.msc as an administrator to open the Group Policy Editor. Navigate to "Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell." Enable the "Turn on Script Execution" policy and select the "Allow all scripts" option. Then, set the registry entry via PowerShell:
Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\PowerShell -Name ExecutionPolicy -Value ByPass
Note: If encountering the error "Set-ExecutionPolicy : Cannot set execution policy. Execution policies at the MachinePolicy or UserPolicy scopes must be set through Group Policy," modifications must be made through the Group Policy Editor.
Step 2: Configure TLS Protocol
Execute the following command in a PowerShell session to ensure TLS 1.2 protocol usage:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
For environments requiring persistent configuration, this command can be added to the PowerShell profile ($PROFILE).
Step 3: Re-register Module Repository
Execute the Register-PSRepository -Default command to re-register the PowerShell Gallery. Then use Get-PSRepository | fl * to verify the configuration, ensuring SourceLocation points to https://www.powershellgallery.com/api/v2 and InstallationPolicy is set to Trusted.
Step 4: Install Modules with Appropriate Scope
If system-level installation still fails, attempt user-scope installation:
Install-Module DBATools -Scope CurrentUser
For cases where older versions exist, add the -Force parameter to force installation.
In-depth Technical Principles
PowerShell Module Management Architecture
PowerShell uses the PackageManagement framework (also known as OneGet) to manage modules. When Install-Module is executed, the system connects to configured repository sources through registered package providers (e.g., NuGet). Connection failures typically stem from network protocol mismatches or security policy restrictions.
Execution Policy Hierarchy
PowerShell execution policies follow a specific priority order: MachinePolicy (highest) > UserPolicy > Process > CurrentUser > LocalMachine (lowest). Group Policy settings reside at the highest level, thus overriding settings in other scopes. Understanding this hierarchy is crucial for diagnosing execution issues.
TLS Protocol Negotiation Mechanism
.NET Framework's ServicePointManager manages HTTP connection protocol negotiations. Older systems may default to TLS 1.0 or SSL 3.0, while the PowerShell Gallery has disabled these insecure protocols. Explicitly setting TLS 1.2 avoids protocol negotiation failures.
Preventive Measures and Best Practices
To prevent similar issues, the following measures are recommended in enterprise environments:
- Uniformly configure PowerShell execution policies via Group Policy to avoid conflicts across scopes
- Pre-configure TLS 1.2 protocol support in system images
- Regularly verify PSGallery repository connection status and trust settings
- Maintain internal mirrored repositories for commonly used modules to reduce dependency on external sources
- Establish standardized module installation procedures, including protocol checks, repository verification, and execution policy confirmation
Conclusion
The error "No match was found for the specified search criteria and module name" is typically not caused by a single issue but results from multiple factors: Group Policy restrictions, protocol configuration, repository status, and installation scope. Through systematic troubleshooting—first adjusting Group Policy settings, then configuring TLS protocol, verifying repository registration, and finally selecting the appropriate installation scope—this problem can be effectively resolved. PowerShell management in enterprise environments requires balancing security policies with functional needs, establishing standardized configuration and management processes.