繁体   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