Create AD application with VSTS task

跟風遠走 提交于 2019-12-06 04:32:18

If you don't need Powershell scripting, go install Azure AD Application Management extension from https://marketplace.visualstudio.com/items?itemName=RalphJansen.Azure-AD-Application-Management You can add new tasks from pipeline GUI for managing AD applications.

If you do need Powershell scripting, then things get tricky. Get Powershell code from https://stackoverflow.com/a/51848069/1548275 as a base. The difference is, that if you're not running your code from an extension, you don't have Get-VstsInput nor Get-VstsEndpoint available to execute.

Also, you don't have AzureAD module cmdlets to run. You need to get the Nuget-package, unzip it to your own repo and have it as part of your scripts to be later Import-Module in a pipeline task.

Finally, you need an auth token for Graph API. As the extension code shows, you will need 3 variables:

  • $tenantId = (Get-AzureRmSubscription).TenantId
  • $clientId = (Get-AzureRmADServicePrincipal -DisplayName "Your Project Service Connection name from Azure AD App Registrations").ApplicationId.Guid
  • $clientSecret = 'hard-coded, reset SPN password'

As you can see, an extension would have access to all three, but regular script (to my knowledge) doesn't.

SPN password reset is covered in The Net. Briefly, it is something like this:

$clientId = (Get-AzureRmADServicePrincipal -DisplayName "Your Project Service Connection name from Azure AD App Registrations").Id.Guid
$password = ConvertTo-SecureString –asplaintext –force "oh, this is very secret!"
New-AzureRmADSpCredential -ObjectId $clientId -Password $password

Also: Update the plaintext password into Azure DevOps project settings, Service Connections for Pipeline to know about the update.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!