-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIntuneCompareUser.ps1
More file actions
192 lines (164 loc) · 6.56 KB
/
Copy pathIntuneCompareUser.ps1
File metadata and controls
192 lines (164 loc) · 6.56 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<#
.SYNOPSIS
Compares multiple users in Microsoft Entra ID (Azure AD) based on selected properties and group memberships.
.DESCRIPTION
This script allows you to compare multiple users in Microsoft Entra ID (Azure AD).
After signing in with your own user account, you will be prompted to enter the number of users and then the UserPrincipalNames or ObjectIds of the users to compare.
The script outputs selected properties (DisplayName, Mail, AccountEnabled) of all users side by side.
Additionally, it compares the group memberships of all users and lists which groups are missing for each user.
.NOTES
Filename: IntuneCompareUser.ps1
Requirements:
- PowerShell with internet access
- AzureAD module installed (will be installed automatically if missing)
- Permission to read user and group information in Entra ID (Azure AD)
.AUTHOR
Ronny Alhelm
.VERSION
1.2.0
.VERSIONHISTORY
1.0.0 - Initial version
1.1.0 - Added group membership comparison
1.2.0 - Support for comparing multiple users
.EXAMPLE
.\IntuneCompareUser.ps1
# After entering the number of users and their UserPrincipalNames or ObjectIds, the main properties and group memberships of all users will be compared and displayed.
#>
# Install the AzureAD module if not already present
if (-not (Get-Module -ListAvailable -Name AzureAD)) {
Install-Module -Name AzureAD -Force -Scope CurrentUser
}
# Sign in with your user account
Connect-AzureAD
# Prompt for number of users
$userCount = Read-Host "How many users do you want to compare?"
if (-not ($userCount -as [int]) -or $userCount -lt 2) {
Write-Host "Please enter a valid number (at least 2)." -ForegroundColor Red
exit 1
}
# Prompt for user identifiers
$userIds = @()
for ($i = 1; $i -le $userCount; $i++) {
$userId = Read-Host "Enter the UserPrincipalName or ObjectId of user $i"
$userIds += $userId
}
# Get user objects
$users = @()
foreach ($id in $userIds) {
$user = Get-AzureADUser -ObjectId $id
if ($null -eq $user) {
Write-Host "User '$id' not found." -ForegroundColor Red
exit 1
}
$users += $user
}
# Compare selected properties
$comparison = foreach ($user in $users) {
[PSCustomObject]@{
DisplayName = $user.DisplayName
Mail = $user.Mail
AccountEnabled = $user.AccountEnabled
}
}
Write-Host "`nUser Properties:" -ForegroundColor Cyan
$comparison | Format-Table -AutoSize
# Compare group memberships
$userGroups = @{}
foreach ($user in $users) {
$groups = Get-AzureADUserMembership -ObjectId $user.ObjectId | Where-Object {$_.ObjectType -eq "Group"}
$userGroups[$user.DisplayName] = $groups.DisplayName
}
Write-Host "`nGroup Membership Differences:" -ForegroundColor Cyan
foreach ($user in $users) {
$otherUsers = $users | Where-Object { $_.ObjectId -ne $user.ObjectId }
$otherGroupNames = $otherUsers | ForEach-Object { $userGroups[$_.DisplayName] } | Select-Object -Unique
$missingGroups = $otherGroupNames | Where-Object { $_ -notin $userGroups[$user.DisplayName] }
Write-Host "`nGroups assigned to at least one other user but missing for $($user.DisplayName):" -ForegroundColor Yellow
if ($missingGroups) {
$missingGroups | ForEach-Object { Write-Host $_ }
} else {
Write-Host "None"
}
}
<#
.SYNOPSIS
Compares multiple users in Microsoft Entra ID (Azure AD) based on selected properties and group memberships.
.DESCRIPTION
This script allows you to compare multiple users in Microsoft Entra ID (Azure AD).
After signing in with your own user account, you will be prompted to enter the number of users and then the UserPrincipalNames or ObjectIds of the users to compare.
The script outputs selected properties (DisplayName, Mail, AccountEnabled) of all users side by side.
Additionally, it compares the group memberships of all users and lists which groups are missing for each user.
.NOTES
Filename: IntuneCompareUser.ps1
Requirements:
- PowerShell with internet access
- AzureAD module installed (will be installed automatically if missing)
- Permission to read user and group information in Entra ID (Azure AD)
.AUTHOR
Ronny Alhelm
.VERSION
1.2.0
.VERSIONHISTORY
1.0.0 - Initial version
1.1.0 - Added group membership comparison
1.2.0 - Support for comparing multiple users
.EXAMPLE
.\IntuneCompareUser.ps1
# After entering the number of users and their UserPrincipalNames or ObjectIds, the main properties and group memberships of all users will be compared and displayed.
#>
# Install the AzureAD module if not already present
if (-not (Get-Module -ListAvailable -Name AzureAD)) {
Install-Module -Name AzureAD -Force -Scope CurrentUser
}
# Sign in with your user account
Connect-AzureAD
# Prompt for number of users
$userCount = Read-Host "How many users do you want to compare?"
if (-not ($userCount -as [int]) -or $userCount -lt 2) {
Write-Host "Please enter a valid number (at least 2)." -ForegroundColor Red
exit 1
}
# Prompt for user identifiers
$userIds = @()
for ($i = 1; $i -le $userCount; $i++) {
$userId = Read-Host "Enter the UserPrincipalName or ObjectId of user $i"
$userIds += $userId
}
# Get user objects
$users = @()
foreach ($id in $userIds) {
$user = Get-AzureADUser -ObjectId $id
if ($null -eq $user) {
Write-Host "User '$id' not found." -ForegroundColor Red
exit 1
}
$users += $user
}
# Compare selected properties
$comparison = foreach ($user in $users) {
[PSCustomObject]@{
DisplayName = $user.DisplayName
Mail = $user.Mail
AccountEnabled = $user.AccountEnabled
}
}
Write-Host "`nUser Properties:" -ForegroundColor Cyan
$comparison | Format-Table -AutoSize
# Compare group memberships
$userGroups = @{}
foreach ($user in $users) {
$groups = Get-AzureADUserMembership -ObjectId $user.ObjectId | Where-Object {$_.ObjectType -eq "Group"}
$userGroups[$user.DisplayName] = $groups.DisplayName
}
Write-Host "`nGroup Membership Differences:" -ForegroundColor Cyan
foreach ($user in $users) {
$otherUsers = $users | Where-Object { $_.ObjectId -ne $user.ObjectId }
$otherGroupNames = $otherUsers | ForEach-Object { $userGroups[$_.DisplayName] } | Select-Object -Unique
$missingGroups = $otherGroupNames | Where-Object { $_ -notin $userGroups[$user.DisplayName] }
Write-Host "`nGroups assigned to at least one other user but missing for $($user.DisplayName):" -ForegroundColor Yellow
if ($missingGroups) {
$missingGroups | ForEach-Object { Write-Host $_ }
} else {
Write-Host "None"
}
}