-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathADEnumerator.ps1
More file actions
143 lines (118 loc) · 4.74 KB
/
ADEnumerator.ps1
File metadata and controls
143 lines (118 loc) · 4.74 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
# ADEnumerator.ps1
# Active Directory Account Enumeration Script
# Requires ActiveDirectory PowerShell module
# Check if AD module is installed
if (-not (Get-Module -ListAvailable -Name ActiveDirectory)) {
Write-Host "ActiveDirectory module is not installed. Please install RSAT tools or run this on a domain controller." -ForegroundColor Red
exit
}
# Import the Active Directory module
Import-Module ActiveDirectory
function Get-ADAccountSummary {
[CmdletBinding()]
param()
Write-Host "`n=== Active Directory Account Summary ===" -ForegroundColor Cyan
# Get all users
$allUsers = Get-ADUser -Filter *
$enabledUsers = $allUsers | Where-Object {$_.Enabled -eq $true}
$disabledUsers = $allUsers | Where-Object {$_.Enabled -eq $false}
# Get all groups
$allGroups = Get-ADGroup -Filter *
Write-Host "`nTotal Users: $($allUsers.Count)"
Write-Host "Enabled Users: $($enabledUsers.Count)"
Write-Host "Disabled Users: $($disabledUsers.Count)"
Write-Host "Total Groups: $($allGroups.Count)"
}
function Get-ADPrivilegedAccounts {
[CmdletBinding()]
param()
Write-Host "`n=== Privileged Account Analysis ===" -ForegroundColor Cyan
# Check Domain Admins
$domainAdmins = Get-ADGroupMember "Domain Admins" -Recursive | Get-ADUser -Properties LastLogonDate, Enabled
Write-Host "`nDomain Admins:" -ForegroundColor Yellow
$domainAdmins | Format-Table Name, Enabled, LastLogonDate -AutoSize
# Check Enterprise Admins
try {
$enterpriseAdmins = Get-ADGroupMember "Enterprise Admins" -Recursive | Get-ADUser -Properties LastLogonDate, Enabled
Write-Host "`nEnterprise Admins:" -ForegroundColor Yellow
$enterpriseAdmins | Format-Table Name, Enabled, LastLogonDate -AutoSize
} catch {
Write-Host "Enterprise Admins group not accessible in this context." -ForegroundColor Yellow
}
}
function Get-ADInactiveAccounts {
[CmdletBinding()]
param(
[int]$DaysInactive = 90
)
Write-Host "`n=== Inactive Account Analysis ===" -ForegroundColor Cyan
$date = (Get-Date).AddDays(-$DaysInactive)
$inactiveUsers = Get-ADUser -Filter {LastLogonDate -lt $date -and Enabled -eq $true} -Properties LastLogonDate |
Select-Object Name, SamAccountName, LastLogonDate
Write-Host "`nInactive accounts (not logged in for $DaysInactive days):" -ForegroundColor Yellow
$inactiveUsers | Format-Table -AutoSize
}
function Get-ADPasswordPolicy {
[CmdletBinding()]
param()
Write-Host "`n=== Password Policy Analysis ===" -ForegroundColor Cyan
$policy = Get-ADDefaultDomainPasswordPolicy
$policy | Format-List ComplexityEnabled, MinPasswordLength, PasswordHistoryCount, MaxPasswordAge, MinPasswordAge, LockoutThreshold, LockoutDuration
}
function Get-ADRecentlyCreatedAccounts {
[CmdletBinding()]
param(
[int]$DaysBack = 30
)
Write-Host "`n=== Recently Created Accounts ===" -ForegroundColor Cyan
$date = (Get-Date).AddDays(-$DaysBack)
$newAccounts = Get-ADUser -Filter {Created -gt $date} -Properties Created |
Select-Object Name, SamAccountName, Created
Write-Host "`nAccounts created in the last $DaysBack days:" -ForegroundColor Yellow
$newAccounts | Format-Table -AutoSize
}
# Main menu function
function Show-Menu {
Clear-Host
Write-Host "=== Active Directory Account Enumeration Tool ===" -ForegroundColor Cyan
Write-Host "1. Get Account Summary"
Write-Host "2. List Privileged Accounts"
Write-Host "3. Find Inactive Accounts"
Write-Host "4. Show Password Policy"
Write-Host "5. Show Recently Created Accounts"
Write-Host "6. Run All Reports"
Write-Host "Q. Quit"
Write-Host
}
# Main script loop
do {
Show-Menu
$selection = Read-Host "Please make a selection"
switch ($selection) {
'1' { Get-ADAccountSummary; pause }
'2' { Get-ADPrivilegedAccounts; pause }
'3' {
$days = Read-Host "Enter number of days for inactivity threshold (default: 90)"
if ([string]::IsNullOrWhiteSpace($days)) { $days = 90 }
Get-ADInactiveAccounts -DaysInactive $days
pause
}
'4' { Get-ADPasswordPolicy; pause }
'5' {
$days = Read-Host "Enter number of days to look back (default: 30)"
if ([string]::IsNullOrWhiteSpace($days)) { $days = 30 }
Get-ADRecentlyCreatedAccounts -DaysBack $days
pause
}
'6' {
Get-ADAccountSummary
Get-ADPrivilegedAccounts
Get-ADInactiveAccounts
Get-ADPasswordPolicy
Get-ADRecentlyCreatedAccounts
pause
}
'Q' { return }
'q' { return }
}
} while ($true)