1
votes

I am trying to register an Azure Active Directory application in Azure, using Powershell commands. It works well when I use Powershell on my laptop, but when I use the same command in Azure DevOps Release pipeline (inside Azure Powershell task), it fails. What can be the reason?

I have tried the following:

  1. It works well when I run the command in local powershell (on my local machine)
  2. I tried the same command in Azure DevOps with different Powershell versions (there is a field for specifying this in the Azure Powershell Script task), but it fails.

$appName = "MyApplication" $appURI = "https://myapplication.azurewebsites.net" $appHomePageUrl = "https://myapplication.xxxxx.nl" $appReplyURLs = @($appURI, $appHomePageURL, "https://localhost:12345") $myApp = New-AzureADApplication -DisplayName $appName -IdentifierUris $appURI -Homepage $appHomePageUrl -ReplyUrls $appReplyURLs

Following is the error messages that I get:

2019-07-29T18:22:10.1100918Z ##[command]Import-Module -Name C:\Modules\az_1.0.0\Az.Accounts\1.6.0\Az.Accounts.psd1 -Global 2019-07-29T18:22:17.0434281Z ##[warning]Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide 2019-07-29T18:22:25.8019093Z ##[command]Clear-AzContext -Scope Process 2019-07-29T18:22:27.9638440Z ##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue 2019-07-29T18:22:28.5285827Z ##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud 2019-07-29T18:22:30.4391614Z ##[command] Set-AzContext -SubscriptionId

######## -TenantId *** 2019-07-29T18:22:30.9129390Z ##[command]& 'd:\a_temp##############.ps1' 2019-07-29T18:22:33.6730996Z

[command]Disconnect-AzAccount -Scope Process -ErrorAction Stop 2019-07-29T18:22:33.8889503Z ##[command]Clear-AzContext -Scope Process

-ErrorAction Stop 2019-07-29T18:22:34.4461613Z ##[error]The term 'New-AzureADApplication' 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. 2019-07-29T18:22:34.7040074Z ##[section]Finishing: Azure PowerShell script: Register an AAD app and generate credential for the same

1

1 Answers

0
votes

There appears to be an issue related to the documentation, the Azure Powershell Task is asking for the module version, not the powershell version.

Commentor here suggests trying 1.0.0 :

https://github.com/MicrosoftDocs/vsts-docs/issues/4850