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
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:
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
Then you won't have issue with
Get-AzSubscription ( after using Connect)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With