簡體   English   中英

在 windows 10 上安裝 Azure PowerShell 模塊

[英]Install the Azure PowerShell module on windows 10

再會!

嘗試在我的 windows 10 機器上安裝 azure AZ 模塊時出現以下錯誤。 任何幫助和建議表示贊賞。 謝謝你。

PS C:\WINDOWS\system32> Install-Module -Name Az -AllowClobber

需要 NuGet 提供程序才能繼續 PowerShellGet 需要 NuGet 提供程序版本“2.8.5.201”或更高版本才能與基於 NuGet 的存儲庫進行交互。 NuGet 提供程序必須在“C:\Program Files\PackageManagement\ProviderAssemblies”或“C:\Users\user\AppData\Local\PackageManagement\ProviderAssemblies”中可用。 您還可以通過運行“Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force”來安裝 NuGet 提供程序。 您希望 PowerShellGet 現在安裝和導入 NuGet 提供程序嗎? [Y] 是 [N] 否 [S] 暫停 [?] 幫助(默認為“Y”):是 警告:無法從 URI 下載https://go.microsoft.com/fwlink/?LinkID=627338&clcid= 0x409 '到''。 警告:無法下載可用提供程序的列表。 檢查您的互聯網連接。 PackageManagement\Install-PackageProvider:未找到提供程序“NuGet”的指定搜索條件的匹配項。 package 提供程序需要“PackageManagement”和“Provider”標簽。 請檢查指定的package是否有標簽。 在 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7468 char:21 +... $null = PackageManagement\Install-PackageProvider -Name $script:N... + ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ + CategoryInfo: InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac kageProvider], Exception + FullyQualifiedErrorId: NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro vider

PackageManagement\Import-PackageProvider:未找到指定搜索條件和提供程序名稱“NuGet”的匹配項。 嘗試“Get-PackageProvider -ListAvailable”以查看系統上是否存在提供程序。 在 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7474 char:21 +... $null = PackageManagement\Import-PackageProvider -Name $script:Nu... + ~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ + CategoryInfo: InvalidData: (NuGet:String) [Import-PackageProvider], 異常 + FullyQualifiedErrorId: NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv ider

警告:無法從 URI“ https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409 ”下載到“”。 警告:無法下載可用提供程序的列表。 檢查您的互聯網連接。 PackageManagement\Get-PackageProvider:找不到 package 提供程序“NuGet”。 它可能尚未導入。 嘗試“Get-PackageProvider -ListAvailable”。 在 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7478 char:30 +... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet... + ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo: ObjectNotFound: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvider], 異常 + FullyQualifiedErrorId: UnknownProviderFromActivatedList,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka geProvider

安裝模塊:NuGet 提供程序需要與基於 NuGet 的存儲庫進行交互。 請確保安裝了“2.8.5.201”或更新版本的 NuGet 提供程序。 在 line:1 char:1 + Install-Module -Name Az -AllowClobber + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~ + CategoryInfo: InvalidOperation: (:) [Install-Module], InvalidOperationException + FullyQualifiedErrorId: CouldNotInstallNuGetProvider,Install-Module

@SumanthMarigowda-MSFT 非常感謝,終於可以安裝 PowershellGet/Azure Powershell 模塊

[following https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-5.1.0 to install Azure Module on Powershell which needs Powershell Get which in turn needs NuGet]

PS C:\WINDOWS\system32> Install-Module -Name PowershellGet -Force

需要 NuGet 提供程序才能繼續PowerShellGet 需要 NuGet 提供程序版本“2.8.5.201”或更高版本才能與基於 NuGet 的存儲庫進行交互。 NuGet 提供程序必須在“C:\Program Files\PackageManagement\ProviderAssemblies”或“C:\Users\aditgarg\AppData\Local\PackageManagement\ProviderAssemblies”中可用。 您還可以通過運行'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'來安裝 NuGet 提供程序。 您希望 PowerShellGet 現在安裝和導入 NuGet 提供程序嗎? [Y] 是 [N] 否 [S] 暫停 [?] 幫助(默認為“Y”):N

由於提示安裝了 NuGet,我取消上面的命令並發出上面的命令:

PS C:\WINDOWS\system32> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

警告:無法從 URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' 下載到 ''。 警告:無法下載可用提供程序的列表。 檢查您的互聯網連接。 Install-PackageProvider:未找到提供程序“NuGet”的指定搜索條件的匹配項。 package 提供程序需要“PackageManagement”和“Provider”標簽。 請檢查指定的package是否有標簽。 在行:1 字符:1

  • Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
  •  + CategoryInfo: InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception + FullyQualifiedErrorId: NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

您的上述解決方案修復了 NuGet 安裝問題:

PS C:\WINDOWS\system32> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

最后安裝 NuGet

PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

名稱 版本 來源 摘要


nuget 2.8.5.208 https://onege... NuGet OneGet 元包管理器提供程序

PS C:\WINDOWS\system32>

最后安裝 PowershellGet

PS C:\WINDOWS\system32> Install-Module -Name PowerShellGet -Force
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32>
PS C:\WINDOWS\system32> Get-InstalledModule -Name PowerShellGet

Version    Name                                Repository              Description
-------    ----                                ----------                       -----------
2.2.5      PowerShellGet                       PSGallery             PowerShell module with commands for discovering, installing, updating and publishing the PowerShell artifacts like Mo...

現在我們可以安裝 Azure PowerShell 模塊

PS C:\WINDOWS\system32>

if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) {
Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
  'Az modules installed at the same time is not supported.')
} else {
Install-Module -Name Az -AllowClobber -Scope CurrentUser

}

PS C:\WINDOWS\system32> Get-InstalledModule -Name Az

Version    Name                                Repository            Description

5.1.0      Az                                  PSGallery             Microsoft Azure PowerShell - Cmdlets to manage resources in Azure. This module  is compatible with WindowsPowerShell a...

PS C:\WINDOWS\system32>


添加我對嘗試連接到 Azure(登錄)時遇到的問題的評論:

更多問題:

PS C:\WINDOWS\system32> Connect-AzAccount

Do you want to run software from this untrusted publisher?
File C:\Users\aditgarg\Documents\WindowsPowerShell\Modules\Az.Accounts\2.2.1   \Accounts.format.ps1xml is published by CN=Microsoft Corporation, O=Microsoft   Corporation, L=Redmond,
S=Washington, C=US and is not trusted on your system. Only run scripts from    trusted publishers.
[V] Never run  [D] Do not run  [R] Run once  [A] Always run  [?] Help   (default is "D"): Y
[V] Never run  [D] Do not run  [R] Run once  [A] Always run  [?] Help  (default is "D"): A
Connect-AzAccount : The 'Connect-AzAccount' command was found in the module   'Az.Accounts', but the module could not be loaded. For more information, run   'Import-Module Az.Accounts'.
At line:1 char:1
+ Connect-AzAccount
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Connect-AzAccount:String) [],   CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

--嘗試按照上面的建議導入找到的模塊--

PS C:\WINDOWS\system32> Import-Module -Name Az
Import-Module : File C:\Users\aditgarg\Documents\WindowsPowerShell\Modules  \Az\5.1.0\Az.psm1 cannot be loaded because running scripts is disabled on this  system. For more information, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ Import-Module -Name Az
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : SecurityError: (:) [Import-Module], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
PS C:\WINDOWS\system32>

解決方案: https://docs.microsoft.com/en-us/troubleshoot/azure/active-directory/cannot-run-scripts-powershell因為上面的錯誤基本上是說在這個系統上禁用了運行腳本

IE

PS C:\WINDOWS\system32> Set-ExecutionPolicy Unrestricted

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust.   Changing the execution policy might expose you to the security risks described  in the about_Execution_Policies
help topic at https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to    change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help  (default is "N"): Y

(按 Y,A 可能會帶來安全風險) 現在 Connect-AzAccount 可以連接到 Azure(登錄)。

執行命令后將執行策略設置為 Restricted:Set-ExecutionPolicy restricted

The error is caused by the way Windows PowerShell interacts with the NuGet infrastructure delivering both the NuGet Package Provider and the Windows PowerShell Module.

整個基礎設施都使用 SSL/TLS 保護。 這可以防止竊聽和干預中間型攻擊,其中惡意人員將流氓代碼注入純文本通信 stream。

Windows PowerShell 不使用 TLS 1.2 與基礎設施通信,但使用安全性較低的加密協議。 與許多其他基礎設施一樣,NuGet 基礎設施已關閉不太安全的加密協議。 Windows Server 2016 目前與基礎設施交互的最佳方式是使用 TLS 1.2。

運行以下 cmdlet [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

你也可以參考這個鏈接

注意:該命令只影響當前的session,不會持續存在。

您還可以檢查計算機上為客戶端設置的 TLS 版本。 看起來需要客戶端的 TLS 1.0。 (參考: https://powershell.org/forums/topic/wmf-5-1-upgrade-broken-repositories/

TLS 安全相關(參考: https://rnelson0.com/2018/05/17/powershell-in-a-post-tls1-1-world/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM