Last active
August 9, 2022 15:04
-
-
Save malantin/5852ee1e4e6cd33ed59e260565eb36f8 to your computer and use it in GitHub Desktop.
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
# Conntect to Azure AD | |
Connect-AzureAD | |
# Get the Enterprise Application for GitHub Enterprise with EMU | |
$githubEMUenterpriseApp = Get-AzureADServicePrincipal -Filter "Displayname eq 'GitHub Enterprise Managed User'" | |
# Get all groups you want to assign, based on their name | |
$groups = Get-AzureADGroup -all $true | Where-Object {$_.DisplayName -like "Dev*"} | Select displayname,objectid | |
# Loop through all groups and assign them to your Enterprise Application Role | |
# Approles[1] Billing Manager | |
# Approles[2] User | |
# Approles[3] Enterprise Owner | |
ForEach ($group in $groups) { | |
Try { | |
New-AzureADGroupAppRoleAssignment -ObjectId $group.ObjectId -PrincipalId $group.ObjectId -Id $githubEMUenterpriseApp.Approles[2].id -ResourceId $githubEMUenterpriseApp.ObjectId -ErrorAction Stop | |
[PSCustomObject]@{ | |
GroupName = $group.displayname | |
AppliciationAssigned = $true | |
} | |
} | |
catch { | |
[PSCustomObject]@{ | |
GroupName = $group.displayname | |
AppliciationAssigned = $false | |
} | |
} | |
} | |
# Credit goes to LazyAdmin Ruud for his helpful blog post on https://lazyadmin.nl/powershell/add-users-to-azure-ad-application-with-powershell/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment