Issue
Did anyone try to add a user to a VM in a Host Pool using Azure DevOps pipeline and service principal?
I need t build a pipeline that I could add a user name and I would assigned to a host pool
$aadContext = Connect-AzureAD
$svcPrincipal = New-AzureADApplication -AvailableToOtherTenants $true -DisplayName $SPDEV
$svcPrincipalCreds = New-AzureADApplicationPasswordCredential -ObjectId $svcPrincipal.ObjectId
$creds = New-Object System.Management.Automation.PSCredential($svcPrincipal.AppId, (ConvertTo-SecureString $svcPrincipalCreds.Value -AsPlainText -Force))
Add-RdsAccount -DeploymentUrl "https://rdbroker.wvd.microsoft.com" -Credential $creds -ServicePrincipal -AadTenantId $aadContext.TenantId.Guid
#Add User to AVD Host Pool
if (Get-RdsAppGroupUser -TenantName Test -HostPoolName $hostpool -AppGroupName $HostPoolAppGroup -UserPrincipalName $user) -eq
Add-RdsAppGroupUser -TenantName $tenant -HostPoolName $hostpool -AppGroupName $HostPoolAppGroup -UserPrincipalName $user
# Assign the user to the app role
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id
Update-AzWvdHostPool -ResourceGroupName $RG -Name $HostPool -PersonalDesktopAssignmentType Direct
#Add User to AVD Host Pool VM
New-AzRoleAssignment -SignInName $User -RoleDefinitionName "Desktop Virtualization User" -ResourceName $HostPool -ResourceGroupName $RG -ResourceType 'Microsoft.DesktopVirtualization/applicationGroups'
I have this but not sure how to build a pipeline around it.
Solution
Use azure powershell task in your pipeline. In addition, you need to connect your Service Principle via Service connections->Azure Resource Manager.
Answered By - Minxin Yu - MSFT

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.