Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps: Powershell 'Get-AzSubscription' is not recognized

I am deploying an ARM template from azure DevOps using Azure PowerShell as shown below.

enter image description here

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
like image 242
Sakaldeep Yadav Avatar asked Jul 16 '19 10:07

Sakaldeep Yadav


3 Answers

You need to specify the task version: 4.* (Preview) or higher to use the Az powershell module:

enter image description here

Also there is an Azure resource group deployment to deploy ARM template easily:

enter image description here

like image 179
Thomas Avatar answered Oct 19 '22 22:10

Thomas


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
like image 36
Karthikeyan VK Avatar answered Oct 20 '22 00:10

Karthikeyan VK


  1. Search apps and Features - Uninstall the old April 2018 Azure
  2. Follow something like this link https://blog.atwork.at/post/The-new-Azure-PowerShell-Az-module

Then you won't have issue with

Get-AzSubscription   ( after using Connect) 
like image 20
Tom Stickel Avatar answered Oct 19 '22 22:10

Tom Stickel