我正在尝试在 PowerShell 类型 Azure Runbook 中运行 Az 命令。启动时它无法识别 Az 命令并希望我安装 NuGet。现在安装 NuGet 时显示错误。
#Set strong cryptography on 64 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
#Set strong cryptography on 32 bit .Net Framework (version 4 and above)
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord
#Install NuGet
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
#Uninstall AzureRm
Uninstall-AzureRm
#Install Module
Install-Module -Name Az.Accounts -Force
Install-Module -Name Az.Resources -Force
#Import Module
Import-Module -Name Az.Accounts -Force
Import-Module -Name Az.Resources -Force
#Connect to your Azure Account
$Account = Connect-AzAccount -Credential $Cred
Get-AzResource -ResourceGroupName "test"
错误
Install-PackageProvider : No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags. At line:17 char: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
如果您注意到我的Connect-AzAccount运行成功但Get-AzResource抛出错误。
- 是否需要安装 NuGet?
- 我的Connect-AzAccount如何不引发错误。
我的Uninstall-AzureRm失败,但如果我不使用它,它会引发不同的错误。
Get-ChildItem :已加载 AzureRM.Profile。Az 和 AzureRM 模块不能在同一会话中导入,也不能在同一脚本或 Runbook 中使用。
Get-AzResource是否需要导入其他模块?
- 我的本地机器上没有问题。仅在运行手册中有问题。