-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSADCommonGroups.ps1
51 lines (43 loc) · 1013 Bytes
/
MSADCommonGroups.ps1
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
<#
.SYNOPSIS
Find all of the Active Directory groups of which all users are a member.
.DESCRIPTION
.PARAMETER users
An array of the names of the users to compare.
.EXAMPLE
$users = @()
$users += "Gates, Bill"
$users += "Jobs, Steve"
$users += "Wozniak, Steve"
.\MSADCommonGroups $users
#>
[CmdletBinding()]
param(
[parameter(position=0, mandatory=$true)]
[string[]]$users
)
$thisFolder = (Split-Path $MyInvocation.MyCommand.Source)
Set-Location $thisFolder
. ".\fn.ps1"
$userGroups = @()
$groupNames = @()
$i = 0
foreach ($u in $users) {
$groupNames = @()
$groups = (Get-ADUser -filter "Name -eq '$u'" -Properties MemberOf).MemberOf
foreach ($g in $groups) {
$groupNames += (Get-ADGroup $g).Name
}
if ($i -eq 0) {
$userGroups = $groupNames
}
else {
$userGroups = arrayAnd $userGroups $groupNames
}
if ($userGroups.Length -eq 0) {
"No matches"
}
$i++
}
"$($userGroups.Length) groups in common:"
$userGroups | Sort-Object