Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save irwinwilliams/dcec7f60a182b7666555674b5fadbb0d to your computer and use it in GitHub Desktop.

Select an option

Save irwinwilliams/dcec7f60a182b7666555674b5fadbb0d to your computer and use it in GitHub Desktop.
Create azure resource group and assign contributors
#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