Skip to content

Instantly share code, notes, and snippets.

@ivangeorgiev
Last active March 16, 2020 10:20
Show Gist options
  • Save ivangeorgiev/3dc4ad083e9163625df09e476e15f16f to your computer and use it in GitHub Desktop.
Save ivangeorgiev/3dc4ad083e9163625df09e476e15f16f to your computer and use it in GitHub Desktop.
Azure Service Principal Role Assignment

Application ID Servie Principal Secret Resource Group Name Databricks Workspace Name Subscription ID TenantID

function Set-ServicePrincipleRoleAssignment {
param(
[string]$ServicePrincipalName,
[string]$RoleDefinitionName = 'Contributor',
[string]$ResourceGroupName,
[string]$ResourceObjectName
)
$ResourceObject = Get-AzResource -ResourceGroupName $ResourceGroupName -Name $WorkspaceName
$Principal = Get-AzADServicePrincipal -DisplayName $ServicePrincipalName
$Assignment = Get-AzRoleAssignment -ObjectId $Principal.Id -RoleDefinitionName $RoleDefinitionName -Scope $ResourceObject.ResourceId
if ($Assignment) {
Return $False
}
Return New-AzRoleAssignment -ApplicationId $Principal.ApplicationId `
-RoleDefinitionName $RoleDefinitionName `
-Scope $ResourceObject.ResourceId
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment