Created
November 9, 2017 13:19
-
-
Save irwinwilliams/dcec7f60a182b7666555674b5fadbb0d to your computer and use it in GitHub Desktop.
Create azure resource group and assign contributors
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
| #Clear-Host | |
| $classlist - ".\class-list.tsv" #contains a tab-delimited list of object ids, resource group names and locations | |
| $tenant = "guid" | |
| $app_id = "guid" | |
| $app_key = ConvertTo-SecureString "key" -AsPlainText -Force | |
| $cred = New-Object -TypeName pscredential -ArgumentList $app_id, $app_key | |
| Login-AzureRmAccount -Credential $cred -ServicePrincipal -TenantId $tenant | |
| Get-Content $classlist | ForEach-Object { | |
| $tokens = $_ -split "\t" | |
| echo "Current tokens - $tokens" | |
| Remove-AzureRmResourceGroup -Name $tokens[4] -Force | |
| New-AzureRmResourceGroup -Name $tokens[4] -Location $tokens[5] -Force | |
| if ($tokens[0].length -gt 0) { | |
| New-AzureRmRoleAssignment -objectid $tokens[1] -RoleDefinitionName "Contributor" -ResourceGroupName $tokens[4] | |
| } | |
| if ($tokens[3].length -gt 0) { | |
| New-AzureRmRoleAssignment -objectid $tokens[3] -RoleDefinitionName "Contributor" -ResourceGroupName $tokens[4] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment