我正在尝试在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 是否需要导入其他模块?
- 我的本地计算机上没有问题。仅在Runbook中有问题。