1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
[crayon–678056b30b1e6088415454 inline=“true” ]# Import the AzureAD module (or Microsoft.Graph if using that module) Import–Module AzureAD # Or ‘Import-Module Microsoft.Graph’ if using the Microsoft Graph module # Connect to Azure AD Connect–AzureAD # Get all users from Azure AD and their proxyAddresses $users = Get–AzureADUser –All $true | Select–Object ObjectId, UserPrincipalName, ProxyAddresses # Flatten the ProxyAddresses and identify duplicates $allProxyAddresses = @() foreach ($user in $users) { if ($user.ProxyAddresses) { $allProxyAddresses += $user.ProxyAddresses } } # Group by ProxyAddress and filter duplicates $duplicateProxyAddresses = $allProxyAddresses | Group–Object | Where–Object { $_.Count –gt 1 } # Output duplicate proxy addresses if ($duplicateProxyAddresses) { $duplicateProxyAddresses | ForEach–Object { $proxy = $_.Name $occurrences = $_.Count $duplicateUsers = $users | Where–Object { $_.ProxyAddresses –contains $proxy } Write–Host “Duplicate ProxyAddress: $proxy occurs $occurrences times” foreach ($user in $duplicateUsers) { Write–Host “`tUser: $($user.UserPrincipalName) – ObjectId: $($user.ObjectId)” } } } else { Write–Host “No duplicate proxy addresses found.” } |
[/crayon]
Sorry! The Author has not filled his profile.