Application ID Servie Principal Secret Resource Group Name Databricks Workspace Name Subscription ID TenantID
Last active
March 16, 2020 10:20
-
-
Save ivangeorgiev/3dc4ad083e9163625df09e476e15f16f to your computer and use it in GitHub Desktop.
Azure Service Principal Role Assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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