Skip to content

Instantly share code, notes, and snippets.

@joshfinley
Created October 2, 2023 20:01
Show Gist options
  • Save joshfinley/dc48230a841e520433a9884b771d7a09 to your computer and use it in GitHub Desktop.
Save joshfinley/dc48230a841e520433a9884b771d7a09 to your computer and use it in GitHub Desktop.
# Install the AzureAD PowerShell module
Install-Module AzureAD# Authenticate to the tenant
$username = "username@domain.com"
$password = 'YourVeryStrongPassword'
$SecurePassword = ConvertTo-SecureString “$password” -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential($username, $SecurePassword)
Connect-AzureAD -Credential $Credential# Build our users and roles object
$UserRoles = Get-AzureADDirectoryRole | ForEach-Object {
$Role = $_
$RoleDisplayName = $_.DisplayName
$RoleMembers = Get-AzureADDirectoryRoleMember -ObjectID $Role.ObjectID
ForEach ($Member in $RoleMembers) { $RoleMembership = [PSCustomObject]@{
MemberName = $Member.DisplayName
MemberID = $Member.ObjectID
MemberOnPremID = $Member.OnPremisesSecurityIdentifier
MemberUPN = $Member.UserPrincipalName
MemberType = $Member.ObjectType
RoleID = $Role.RoleTemplateId
RoleDisplayName = $RoleDisplayName
}
$RoleMembership
}
}$UserRoles | ?{$_.MemberType -eq "ServicePrincipal"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment