-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSADOwnedGroups.ps1
50 lines (34 loc) · 999 Bytes
/
MSADOwnedGroups.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
"
------------------------
"
$functions = Join-Path $env:USERPROFILE "repos\CognosAdmin\RESTAPI\fn.ps1"
. $functions
$user = Read-Host "Group Owner"
$groups = Get-ADGroup -Filter '*' -Properties nTSecurityDescriptor
$l = $groups.Count
$objName = "group"
# $a = @()
$b = @()
$i = 0
Write-Host "$l groups in Active Directory"
$startTime = Get-Date
foreach ($g in $groups) {
if ($g.nTSecurityDescriptor.Owner -eq $user) {
# $a += $g
$b += get-ADPath -DistinguishedName $g.DistinguishedName -BasePath "WSDOT.LOC" -BasePathLength 2
}
$i++
$p = [int]($i * 100 / $l)
$elapsed = ((Get-Date) - $startTime).TotalSeconds
$remainingItems = $l - $i
$averageItemTime = $elapsed / $i
Write-Progress "Processing $l $($objName)s" `
-Status "$i $($objName)s processed" `
-PercentComplete $p `
-SecondsRemaining ($remainingItems * $averageItemTime)
}
Write-Host "$($b.Length) groups owned by $user
"
foreach ($c in $b) {
Write-Host $c
}