azure - 在 Windows 10 上安装 Azure PowerShell 模块

标签 azure

美好的一天!

尝试在我的 Windows 10 计算机上安装 azure AZ 模块时出现以下错误。任何帮助和建议表示赞赏。谢谢。

PS C:\WINDOWS\system32> 安装模块 -Name Az -AllowClobber

需要 NuGet 提供程序才能继续 PowerShellGet 需要 NuGet 提供程序版本“2.8.5.201”或更高版本才能与基于 NuGet 的存储库进行交互。努 git 提供程序必须在“C:\Program Files\PackageManagement\ProviderAssemblies”中可用,或者 'C:\Users\user\AppData\Local\PackageManagement\ProviderAssemblies'。您还可以通过运行来安装 NuGet 提供程序 “安装-PackageProvider -名称 NuGet -MinimumVersion 2.8.5.201 -Force”。您想要安装并导入 PowerShellGet 现在是 NuGet 提供商吗? [Y] 是 [N] 否 [S] 暂停 [?] 帮助(默认为“Y”):是 警告:无法从 URI ' https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409 下载' 到 ''。 警告:无法下载可用提供商的列表。检查您的互联网连接。 PackageManagement\Install-PackageProvider :未找到与提供程序的指定搜索条件匹配的内容 “努盖特”。包提供程序需要“PackageManagement”和“Provider”标签。请检查是否是指定的包 有标签。 在 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7468 char:21 + ... $null = PackageManagement\Install-PackageProvider -名称 $script:N ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~ + 类别信息:无效参数:(Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac kageProvider],异常 +FullyQualifiedErrorId:NoMatchFoundForProvider、Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro 维德尔

PackageManagement\Import-PackageProvider:未找到与指定的搜索条件和提供程序名称匹配的内容 “努盖特”。尝试“Get-PackageProvider -ListAvailable”以查看系统上是否存在该提供程序。 在 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7474 char:21 + ... $null = PackageManagement\Import-PackageProvider -名称 $script:Nu ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~ + CategoryInfo:无效数据:(NuGet:String) [Import-PackageProvider],异常 +FullyQualifiedErrorId:NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProv 伊德尔

警告:无法从 URI“https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409”下载' 到 ''。 警告:无法下载可用提供商的列表。检查您的互联网连接。 PackageManagement\Get-PackageProvider:无法找到包提供程序“NuGet”。可能还没有导入。尝试 '获取PackageProvider -ListAvailable'。 在 C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7478 char:30 + ... tProvider = PackageManagement\Get-PackageProvider -名称 $script:NuGet ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~ + 类别信息:ObjectNotFound:(Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvi der],异常 + FullQualifiedErrorId:UnknownProviderFromActivatedList、Microsoft.PowerShell.PackageManagement.Cmdlets.GetPacka geProvider

Install-Module:需要 NuGet 提供程序才能与基于 NuGet 的存储库进行交互。请确保“2.8.5.201” 或已安装更新版本的 NuGet 提供程序。 行:1 字符:1 + 安装模块 -Name Az -AllowClobber + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [安装模块],InvalidOperationException + FullQualifiedErrorId:CouldNotInstallNuGetProvider,安装模块

最佳答案

@SumanthMarigowda-MSFT 非常感谢,终于可以安装 PowershellGet/Azure Powershell 模块了

[以下 https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-5.1.0 在 Powershell 上安装 Azure 模块,需要 Powershell Get,而 Powershell Get 又需要 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'。您还可以通过运行来安装 NuGet 提供程序 “Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force”。您希望 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”的指定搜索条件匹配的内容。包提供程序需要“PackageManagement”和“Provider”标签。请 检查指定的包是否有标签。 在行: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...OneGet 元包管理器的 NuGet 提供程序

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://learn.microsoft.com/en-us/troubleshoot/azure/active-directory/cannot-run-scripts-powershell因为上面的错误基本上表明运行脚本在此系统上被禁用

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 受限制

关于azure - 在 Windows 10 上安装 Azure PowerShell 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61285186/

相关文章:

azure - 液态体内返回应对政策

Azure 管道(开发运营): Custom Consumable Statistic/Metric

azure - azure 幂等操作的模式?

azure - 确定 Azure VM 启动时间的正确方法是什么?

azure - 使用 CLI 将公共(public)证书上传到 Azure Function App

无法设置 Azure VM DNS 名称标签

azure - 如何在 Cosmos DB 中使用很长的复合索引?

c# - 发布时 Azure SDK 存储程序集未找到异常

azure - 在 Multi-Tenancy 函数应用程序中访问图形 API

azure - 在哪里可以找到 azure web app linux 的 ftp 凭据?