Created
January 30, 2019 23:12
-
-
Save jkbryan/ad0c9473a49d7550a184f36135e0cf35 to your computer and use it in GitHub Desktop.
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