添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I am facing to this problem for a few days and already loosing my mind :D. I would really appreciate your help.

My problem is that I am not able to install modules to my powershell console.

Example: Install-module -Name AzureAD

PS C:\WINDOWS\system32> Install-module -Name AzureAD  
PackageManagement\Install-PackageProvider : Unable to find repository with SourceLocation ''. Use Get-PSRepository to see all available repositories.  
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:3138 char:21  
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...  
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception  
    + FullyQualifiedErrorId : RegisterPackageSourceRequired,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider  
PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name 'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the sys  
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:3144 char:21  
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...  
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    + CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider], Exception  
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider  
PackageManagement\Get-PackageProvider : Unable to find package provider 'NuGet'. It may not be imported yet. Try 'Get-PackageProvider -ListAvailable'.  
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:3148 char:30  
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...  
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvider], Exception  
    + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider  
Install-module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.  
At line:1 char:1  
+ Install-module -Name AzureAD  
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    + CategoryInfo          : InvalidOperation: (:) [Install-Module], InvalidOperationException  
    + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module  

I know that there is missing the NuGet provider. So I have tried to copy that from another computer AND?

PS C:\WINDOWS\system32> Install-Module -Name AzureAD  
PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).  
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:9709 char:34  
+ ... talledPackages = PackageManagement\Install-Package @PSBoundParameters  
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
    + CategoryInfo          : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception  
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage  

I am literary stuck at this point. Anybody who was facing to this problem or know how to fix it?

Thank you!

What have you attempted so far? Kinda hard to help without knowing that :)

One thing, you want force tls 1.2
so run this and then see if it gets you any further.

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

ha what I have attempted? Well a couple of things already. Already tried the TLS but it didn´t worked. I also tried to manually install/import the nuget and poweshellget. Register the nuget package source location.

What strange is (I thought that I got it working but...):
Nuget is imported from different computer, where powershell is working (copied the .dll file from "C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll")

https://www.codepile.net/pile/6P2RDrP4

I had the exact same issue but I was attempting to install the MicrosoftTeams module on a Windows Server 2022. Once I had run:

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

I was able to run:

Install-Module -Name MicrososftTeams -Force -AllowClobber

@GilakOndrej-3552 · You can run save-module AzureAD -Path C:\temp on any working machine, copy the C:\temp\AzureAD folder to the non-working machine and run below command on the non-working machine to import the module:
Import-module C:\test\AzureAD
That way you can use the module without having to spend time on fixing the NuGet issue.

Hi @GilakOndrej-3552 · What is the OS? What version of Windows Management Framework you are using. If you don't have it installed please refer to https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf/setup/install-configure?view=powershell-7. If you have WMF 5.0, try to uninstall that and install 5.1. If you are still facing the issue, try capturing network trace using netmon or wireshark to make sure that nuget.org traffic is not getting blocked. You can also try installing latest (pre-release) version of PowerShell from: https://github.com/PowerShell/PowerShell/releases/download/v7.1.0-rc.2/PowerShell-7.1.0-rc.2-win-x64.msi

Hi @AmanpreetSingh-MSFT I am using Windows 10 (2004) and I have WMF up to date
PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value   
----                           -----   
PSVersion                      5.1.19041.546  
PSEdition                      Desktop  
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}  
BuildVersion                   10.0.19041.546  
CLRVersion                     4.0.30319.42000  
WSManStackVersion              3.0  
PSRemotingProtocolVersion      2.3  
SerializationVersion           1.1.0.1   

I´ll try capture the network soon. And I am able to use PS7, that is working fine.

@GilakOndrej-3552 · Here is the installer for latest release of PowerShell releaser: https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/PowerShell-7.0.3-win-x64.msi.

If you don't want to use pre-release i.e., 7.1.0, you can use the latest release which is 7.0.3.

Read more: https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-7

Hi, no change :/

PS C:\WINDOWS\system32> $wc = New-Object System.Net.WebClient
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
PS C:\WINDOWS\system32> Install-Module azuread
PackageManagement\Install-Package : Unable to find module providers (PowerShellGet).
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:9709 char:34
+ ... talledPackages = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : UnknownProviders,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
PS C:\WINDOWS\system32> 
						

This might be due to the fact that TLS1.0 is no longer supported for psgallery.
You can read more here:
https://dev.to/darksmile92/powershell-disabled-support-for-tls-1-0-for-the-gallery-update-module-and-install-module-broken-1oii

You probably want to use these commando's (you might need to install powershellget again after that)

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Register-PSRepository -Default -Verbose
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted