Automate creation of service principal and adding admin rights

128 Views Asked by At

I have created an azure analysis services resource in a bicep template. Due to it not having any support for managed identity's am going to have to use a service principal. Is there a way in azure cli or powershell where i can create a script that creates a service principal and gives it server admin rights on azure analysis services. azure analysis server admin rights is required as i plan do the following https://learn.microsoft.com/en-us/azure/analysis-services/analysis-services-async-refresh#base-url

1

There are 1 best solutions below

0
Sridevi On BEST ANSWER

You can make use of below PowerShell command to create service principal in your directory:

New-AzADServicePrincipal -DisplayName "sp_name" 

To add this service principal to the Server Administrator role under Azure Analysis Server, run this command:

Set-AzAnalysisServicesServer -Name "aas_name" -ResourceGroupName "rg_name" -Administrator app:appId@tenantId

In my case, I used below PowerShell script to create service principal and adding admin rights to it under Azure Analysis Server:

$sp = New-AzADServicePrincipal -DisplayName "srianalysisapp1601"

$appId = $sp.AppId
$tenantId = $sp.AppOwnerOrganizationId  

Set-AzAnalysisServicesServer -Name "demoanalysis16" -ResourceGroupName "Sri" -Administrator "app:$appId@$tenantId"

Response:

enter image description here

To confirm that, I checked the same in Portal where service principal is added as Analysis Services Admin successfully like this:

enter image description here

References:

New-AzADServicePrincipal (Az.Resources) | Microsoft

Manage server admins in Azure Analysis Services | Microsoft