Grants an Azure Service Principle READ access to the Subscription
This file contains 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
$Subscription = "<Subscription-GUID>" | |
$ApplicationName = "<AppName>" | |
$ServicePrincipal = Get-AzureRMADServicePrincipal -DisplayName $ApplicationName | |
Set-AzureRmContext -Subscription $Subscription | |
$NewRole = $null | |
$Retries = 0; | |
While ($NewRole -eq $null -and $Retries -le 6) { | |
Sleep 15 | |
New-AzureRMRoleAssignment -ResourceGroupName -RoleDefinitionName Reader -ServicePrincipalName $ServicePrincipal.ApplicationId | Write-Verbose -ErrorAction SilentlyContinue | |
$NewRole = Get-AzureRMRoleAssignment -ObjectId $ServicePrincipal.Id -ErrorAction SilentlyContinue | |
$Retries++; | |
} | |
$NewRole |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment