Skip to content

Instantly share code, notes, and snippets.

@malantin
Last active August 9, 2022 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malantin/5852ee1e4e6cd33ed59e260565eb36f8 to your computer and use it in GitHub Desktop.
Save malantin/5852ee1e4e6cd33ed59e260565eb36f8 to your computer and use it in GitHub Desktop.
# 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