Azure DevOps: Powershell 'Get-AzSubscription' is not recognized
18,749
Solution 1
You need to specify the task version: 4.* (Preview)
or higher to use the Az powershell module:
Also there is an Azure resource group deployment
to deploy ARM template easily:
Solution 2
looks like too much confusion among all az modules, MSFT have messed up az new/old modules and are conflicting with each other. az account show
will list all modules with AZ CLI
az account show
Author by
Sakaldeep Yadav
Updated on June 19, 2022Comments
-
Sakaldeep Yadav almost 2 years
I am deploying an ARM template from azure DevOps using Azure PowerShell as shown below.
This is subscription level deployment. I am getting below error.
The term 'Get-AzSubscription' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Install-Module -Name Az -AllowClobber -Scope CurrentUser Import-Module Az $context = Get-AzSubscription -SubscriptionId xxxxxxxx Set-AzContext $context New-azdeployment -Name "SKL" -Location westeurope -TemplateFile .\delegatedResourceManagement.json -TemplateParameterFile .\delegatedResourceManagement.parameters.json
Logs:
##[section]Starting: Azure PowerShell script: InlineScript ============================================================================== Task : Azure PowerShell Description : Run a PowerShell script within an Azure environment Version : 3.153.0 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-powershell ============================================================================== ##[command]Import-Module -Name C:\Modules\azurerm_6.7.0\AzureRM\6.7.0\AzureRM.psd1 -Global ##[command]Clear-AzureRmContext -Scope Process ##[command]Disable-AzureRmContextAutosave -ErrorAction Stop ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope ##[command] Select-AzureRMSubscription -SubscriptionId xxxxxxx -TenantId *** ##[command]& 'd:\a\_temp\xxxxxxd.ps1' ##[warning]User declined to install module (Az). ##[error]The specified module 'Az' was not loaded because no valid module file was found in any module directory. ##[command]Disconnect-AzureRmAccount -Scope Process -ErrorAction Stop ##[command]Clear-AzureRmContext -Scope Process -ErrorAction Stop ##[error]The term 'Get-AzSubscription' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. ##[section]Finishing: Azure PowerShell script: InlineScript
-
Sakaldeep Yadav almost 5 yearsAs my templates will be deployed at the subscription level, Azure resource group deployment won't work. Task version=4.*(preview) worked.thanks.
-
johnstaveley almost 4 yearsUse Version 5 now