title: Using Az module in Azure DevOps Release Pipeline
body: <p>I want to use the <a href="https://docs.microsoft.com/en-us/powershell/azure/overview?view=azps-1.0.0" rel="noreferrer">Azure PowerShell Module</a> (aka Az Module) in an Azure DevOps Release Pipeline. However, the existing PowerShell options don't seem to work. I've tried various things, but installing the new Az module just brings up a ton of errors, including <code>Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook.</code></p>
  
  <p>The regular PowerShell task doesn't have any azure modules built in. And the Azure PowerShell task uses the <a href="https://docs.microsoft.com/en-gb/powershell/azure/azurerm/overview?view=azurermps-6.13.0" rel="noreferrer">Azure RM PowerShell module</a>, which has been retired (i.e. it is still supported, but no new features will be added).</p>
  
  <p>The error, above, is most likely caused because when the Azure PowerShell task start, it performs the following before running my script:</p>
  
  <pre><code>2019-01-13T13:34:14.5416432Z ==============================================================================
  2019-01-13T13:34:14.5416555Z Task         : Azure PowerShell
  2019-01-13T13:34:14.5416623Z Description  : Run a PowerShell script within an Azure environment
  2019-01-13T13:34:14.5416705Z Version      : 3.1.18
  2019-01-13T13:34:14.5416762Z Author       : Microsoft Corporation
  2019-01-13T13:34:14.5416831Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613749)
  2019-01-13T13:34:14.5416969Z ==============================================================================
  2019-01-13T13:34:20.3546127Z ##[command]Import-Module -Name C:\Modules\AzureRm_6.7.0\AzureRM\6.7.0\AzureRM.psd1 -Global
  2019-01-13T13:34:58.4365259Z ##[command]Clear-AzureRmContext -Scope Process
  2019-01-13T13:34:59.2732327Z ##[command]Disable-AzureRmContextAutosave -ErrorAction SilentlyContinue
  2019-01-13T13:35:00.1691359Z ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
  2019-01-13T13:35:01.5702545Z ##[command] Select-AzureRMSubscription -SubscriptionId d5eaaba3-2968-456a-98a4-e53e961fc896 -TenantId ***
  2019-01-13T13:35:02.1592660Z ##[command]&amp; 'D:\a\r1\a\ws-build\tools\install-dependencies.ps1' 
  </code></pre>
  
  <p>Naturally, on a new project I don't want to be creating PowerShell scripts with a module that will no longer be advanced.</p>
  
  <p>And thinking ahead, even if I do manage to get past this, I will have to authenticate somehow with Azure, which the existing Azure DevOps UI does for me, and I can't yet see how to do that with the Az Module.
  <a href="https://i.stack.imgur.com/tZN0Z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tZN0Z.png" alt="Add a subscription into the Azure context"></a></p>
  
  <p>Googling doesn't seem to help, as most information still relates the deprecated AzureRM module. So... In summary.</p>
  
  <p>How do I use the Azure (Az) Powershell module in an Azure DevOps release pipeline?</p>