Last active
September 7, 2022 14:02
-
-
Save pjirsa/5d8d0f5c2d77d55f19504b515bec8649 to your computer and use it in GitHub Desktop.
Create Resource Groups and Assign Owner Role
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
$subscriptionId = "<azure subscription id>" | |
Connect-AzAccount -SubscriptionId $subscriptionId | |
$users = Import-Csv ./userlist.csv | |
foreach ($user in $users) { | |
$user | |
$g = Get-AzResourceGroup -Name $user.AzureGroup -ErrorVariable notFound -ErrorAction SilentlyContinue | |
if ($notFound) { | |
$g = New-AzResourceGroup -Name $user.AzureGroup -Location "Central US" | |
} | |
New-AzRoleAssignment ` | |
-ResourceGroupName $g.ResourceGroupName ` | |
-RoleDefinitionName "Owner" ` | |
-SignInName $user.UserName | |
} |
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
UserName | TeamName | AzureGroup | |
---|---|---|---|
blazor@dodgeball.onmicrosoft.com | Globo Gym | Globo-Gym | |
peter@dodgeball.onmicrosoft.com | Average Joe's | Average-Joes | |
piratesteve@dodgeball.onmicrosoft.com | Average Joe's | Average-Joes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment