Windows

安全配置更新後,Powershell 無法訪問包/“NuGet”包提供程序

  • February 10, 2020

我使用 mof / dsc 配置更新了伺服器,本質上更改了各種權限/系統資料庫項以實現安全合規性。這在某種程度上是自動生成的,我確實有一個已配置的所有內容的列表,但它有點難以閱讀並且不是很清楚。

在此過程之後,powershell 無法更新新包,或設置其預設儲存庫。

我不認為這是 NuGet 特有的東西,我的直覺是它與某種更基本的文件權限有關。據我所知,NuGet 已安裝在我的系統上,我知道它是在應用此配置之前安裝的,並且我所知道的沒有被刪除。

我已經仔細檢查了一個工作伺服器,並且 NuGet .dll 上的權限看起來是一樣的。

下面是一個錯誤範例:

PS C:\Windows\system32> Register-PSRepository -Default
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 system.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7302 char:25
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
   + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv
  ider


NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\opc\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import
the NuGet provider now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y
PackageManagement\Install-PackageProvider : Unable to find repository with SourceLocation ''. Use Get-PSRepository to
see all available repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7405 char:21
+ ...     $null = PackageManagement\Install-PackageProvider -Name $script:N ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
  kageProvider], Exception
   + FullyQualifiedErrorId : RegisterPackageSourceRequired,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPack
  ageProvider

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 system.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7411 char:21
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
   + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv
  ider

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\1.0.0.1\PSModule.psm1:7415 char:30
+ ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvi
  der], Exception
   + FullyQualifiedErrorId : UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka
  geProvider

Register-PSRepository : 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
+ Register-PSRepository -Default
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidOperation: (:) [Register-PSRepository], InvalidOperationException
   + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Register-PSRepository

工作系統上的包提供程序:

PS C:\Windows\system32> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.208        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

損壞系統上的包提供程序(注意,nuget 不再大寫,奇怪,“NuGet”的目錄也是小寫,不確定是否相關:

PS C:\Windows\system32> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
nuget                    2.8.5.208

NuGet 封包件(DLL 確實在這裡,我嘗試用工作系統中的 DLL 替換它,但無濟於事)

PS C:\Windows\system32> gci -Recurse -Filter "nuget" -Directory -ErrorAction SilentlyContinue -Path "C:\"


   Directory: C:\Program Files\PackageManagement\ProviderAssemblies


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        2/10/2020   5:03 PM                nuget

真是太棒了!!!哦,我的話是一個艱難的詞。

這是系統資料庫項:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy

這是我找到的解決方案: https ://windowsserver.uservoice.com/forums/301869-powershell/suggestions/15126048-install-packageprovider-name-nuget-not-working

引用自:https://serverfault.com/questions/1002552