I am trying to run the Az commands inside PowerShell type Azure Runbook. At starting it does not recognize the Az commands and want me to install NuGet. Now error displayed while installing 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 NuGetInstall-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force#Uninstall AzureRmUninstall-AzureRm#Install ModuleInstall-Module -Name Az.Accounts -ForceInstall-Module -Name Az.Resources -Force#Import ModuleImport-Module -Name Az.Accounts -ForceImport-Module -Name Az.Resources -Force#Connect to your Azure Account$Account = Connect-AzAccount -Credential $CredGet-AzResource -ResourceGroupName "test"
Error
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
If you notice that my Connect-AzAccount run successfully but Get-AzResource throw error.
- Is it necessary to install NuGet?
- How my Connect-AzAccount does not throw an error.
My Uninstall-AzureRm is failing but if I don't use it then it throws a different error.
Get-ChildItem : AzureRM.Profile already loaded. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook.
Is Get-AzResource required some other module to import?
- There is no issue at my local machine. Having an issue in runbook only.