azure - 使用 Azure DevOps 注册 Azure Active Directory 应用程序

标签 azure powershell azure-devops azure-active-directory

我正在尝试使用 Powershell 命令在 Azure 中注册 Azure Active Directory 应用程序。当我在笔记本电脑上使用 Powershell 时,它运行良好,但当我在 Azure DevOps Release 管道(在 Azure Powershell 任务内)中使用相同的命令时,它会失败。可能是什么原因?

我尝试过以下方法:

  1. 当我在本地 powershell(在我的本地计算机上)中运行命令时效果很好
  2. 我在 Azure DevOps 中使用不同的 Powershell 版本尝试了相同的命令(Azure Powershell 脚本任务中有一个用于指定此命令的字段),但失败了。

$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

以下是我收到的错误消息:

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

最佳答案

似乎存在与文档相关的问题,Azure Powershell 任务要求提供模块版本,而不是 Powershell 版本。

这里的评论者建议尝试 1.0.0 :

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

关于azure - 使用 Azure DevOps 注册 Azure Active Directory 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57273458/

相关文章:

C# LINQ .Any 不适用于 DocumentDb CreateDocumentQuery

powershell - Powershell 中加号 (+) 的特殊使用

azure - 使用 ADF v2 将“GET MetaData”事件输出到 SQL 表

azure-devops - Azure DevOps 查询匹配未分配的任务?

powershell - 解压缩受密码保护的文件

azure - 如何在发布管道中使用输出变量

azure - 具有 IoT Edge 设备的 IoT 中心的 ARM 模板

node.js - 无法删除 azure 上的 wwwroot

python - 使用存储在 Azure Functions 和容器应用程序的私有(private) Git 存储库中的 python 包?

rest - 在没有用户委托(delegate)的情况下如何使用OAuth? -- 微软图形API