/
Domain_Audit_Summary.ps1
453 lines (398 loc) · 13.2 KB
/
Domain_Audit_Summary.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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<#
.DESCRIPTION
*** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK ***
Forest Information
- Forest Root Domain
- Forest Functional Level
- Domains in the forest
- AD Recycle BIN status
Domain Information
- Domain Functional Level
- NETBIOS name
FSMO Roles
- Domain Naming Master
- Schema Master
- PDC Emulator
- RID Master
- Infrastructure Master
Domain Controller Information
- Domain
- Forest
- Computer Name
- IP Address
- Global Catalog
- Read Only
- Operating System
- Operating System Version
- Site
DNS Information
- Primary Zones
- NS Records
- MX Records
- Forwards
- Scavenging Enabled
- Aging Enabled
DHCP Information
- Computer Name
- IP Address
Site Information
- Site Names
- Intersite Links
- Name
- Site Included
- Site Cost
- Site Replication Frequency
GPO Information
- Domain Name
- Display Name
- Creation Time
- Modification Time
Privileged Account Information
- Enterprise Admin Group Members
- Domain Admin Group Members
- Schema Admin Group Members
- Accounts that Passwords Never Expire
Exchange Information
- Organization Management Group Members
- Exchange Server
.NOTES
File Name: Get-ForestInfo.ps1
Author: David Hall
Contact Info:
Website: www.signalwarrant.com
Twitter: @signalwarrant
Facebook: facebook.com/signalwarrant/
Google +: plus.google.com/113307879414407675617
YouTube Subscribe link: https://www.youtube.com/c/SignalWarrant1?sub_confirmation=1
Requires:
Proper permissions to execute the script in the forest
Execute the script from a Domain Controller, or the preferred
method, on a client with the RSAT installed
Tested: Windows Server 2012 R2, Windows Server 2016, Windows 10, PowerShell v3-5
.PARAMETER(s)
None
.EXAMPLE
Get-ForestInfo.ps1
Inspired by:
Zachary Loeber's script
https://gallery.technet.microsoft.com/office/Active-Directory-Audit-7754a877
#>
#region Variables
######################################
# Variables
######################################
# Get the date for the filename
$date = (Get-Date -Format d_MMMM_yyyy).toString()
# Where to ouput the html file
$filePATH = "$env:userprofile\Desktop\"
# Define the filename
$fileNAME = 'AD_Info_' + $date + '.html'
$File = $filePATH + $fileNAME
$forestInfo = Get-ADForest
$AllDomains = (Get-ADForest).Domains
$domainInfo = Get-ADDomain
$PDCEmulator = (Get-ADDomain).PDCEmulator
$DNSRoot = $domainInfo.dnsroot
$ADsiteLinks = Get-ADReplicationSiteLink -Filter *
#endregion
#region Forest Info
######################################
# Forest Information
######################################
# Forest Root Domain
$RootDomain = $forestInfo.RootDomain
# Forest Functional Level
$ForestMode = $forestInfo.ForestMode
# Forest Domains
$Domains = ($forestInfo |
Select-Object -ExpandProperty Domains) -join ' | '
# AD Recycle BIN Status
$ADRecycleBIN = Get-ADOptionalFeature -filter {Name -eq 'Recycle Bin Feature'} |
Select-Object -ExpandProperty EnabledScopes
If (!$ADRecycleBIN){
$ADRecycleBIN = 'Disabled'
} else {
$ADRecycleBIN = 'Enabled'
}
# Forest Information Output Object
$ForestOutputObj = New-Object -TypeName PSObject
$ForestOutputObj | Add-Member -MemberType NoteProperty -Name ForestRootDomain -Value $RootDomain
$ForestOutputObj | Add-Member -MemberType NoteProperty -Name ForestFunctionalLevel -Value $ForestMode
$ForestOutputObj | Add-Member -MemberType NoteProperty -Name ForestDomains -Value $Domains
$ForestOutputObj | Add-Member -MemberType NoteProperty -Name ADRecycleBIN -Value $ADRecycleBIN
$ForestOutputObjHTML = $ForestOutputObj | ConvertTo-Html
#endregion
#region Domain Info
######################################
# Domain Information
######################################
# Get the Domain Functional Level
$DomainMode = ($DNSRoot | foreach { Get-ADDomain -Identity $_ } |
Select-Object -ExpandProperty DomainMode) -join ' | '
# Get the Domain NetBIOS Name
$NetBIOSName = $domainInfo.netBIOSName
# Domain Information Output Object
$DomainOutputObj = New-Object -TypeName PSObject
$DomainOutputObj | Add-Member -MemberType NoteProperty -Name ForestFunctionalLevel -Value $DomainMode
$DomainOutputObj | Add-Member -MemberType NoteProperty -Name NetBIOS_Name -Value $NetBIOSName
$DomainOutputObjHTML = $DomainOutputObj | ConvertTo-Html
#endregion
#region FSMO Info
######################################
# FSMO Role Information
######################################
# Forest FSMO Roles
$ForestFSMO = $forestInfo | Select-Object -Property DomainNamingMaster,SchemaMaster |
ConvertTo-Html -Fragment
# Domain FSMO Roles
$DomainFSMO = $DNSRoot | foreach { Get-ADDomain -Identity $_ } |
Select-Object -Property PDCEmulator,RIDMaster,InfrastructureMaster |
ConvertTo-Html -Fragment
#endregion
#region DC Info
######################################
# Domain Controllers Information
######################################
# Domain Controller Information
$DCs = Get-ADDomainController -Filter * |
Select-Object -Property Domain,Forest,Name,IPv4Address,IsGlobalCatalog,IsReadOnly,OperatingSystem,OperatingSystemVersion,Site
$DCOutputObjHTML = $DCs | ConvertTo-Html
#endregion
#region DNS Info
######################################
# DNS Information
######################################
# Primary Zone Information
$PrimaryZones = (Get-DnsServerZone -ComputerName $PDCEmulator |
Where-Object {$_.IsReverseLookupZone -eq $False} |
Select-Object -ExpandProperty ZoneName) -join '<br/>'
# NS records
$NSRecords = (Resolve-DnsName -Name $DNSRoot -type ns |
Where-Object {$_.QueryType -eq 'NS'} |
Select-Object -ExpandProperty Server) -join '<br/>'
# MX Records
$MXRecords = (Resolve-DnsName -Name $DNSRoot -type MX |
Where-Object {$_.QueryType -eq 'MX'} |
Select-Object -ExpandProperty Exchange) -join '<br/>'
# Forwarders
$DNSForwarders = (Get-DnsServerForwarder -ComputerName $PDCEmulator |
Select-Object -ExpandProperty IPAddress) -join '<br/>'
# Scavenging (Returns True or False)
$DNSScavenging = (Get-DnsServerScavenging -ComputerName $PDCEmulator).scavengingState
# Aging (Returns True or False)
$DNSAging = (Get-DnsServerZoneAging -Name $DNSRoot -ComputerName $PDCEmulator).AgingEnabled
#endregion
#region DHCP Info
######################################
# DHCP Information
######################################
$DHCP = Get-WindowsFeature -name DHCP |
Where-Object {$_.Installed -eq $True}
If($DHCP){
$DHCPServers = Get-DhcpServerInDC
$DHCPOutputObj = New-Object -TypeName PSObject
$DHCPOutputObj | Add-Member -MemberType NoteProperty -Name Name -Value $DHCPServers.DNSName
$DHCPOutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $DHCPServers.IPAddress
$DHCPOutputObjHTML = $DHCPOutputObj | ConvertTo-Html
} Else {
$DHCPServers = 'No DHCP Found'
$DHCPOutputObj = New-Object -TypeName PSObject
$DHCPOutputObj | Add-Member -MemberType NoteProperty -Name -- -Value $DHCPServers
$DHCPOutputObjHTML = $DHCPOutputObj | ConvertTo-Html
}
#endregion
#region Site Info
######################################
# Site Information
######################################
# All Forest Sites
$Sites = ($forestInfo |
Select-Object -ExpandProperty Sites) -join '<br/>'
# Inter-Site Transport
####### Need a foreachloop for each sites info
$SiteLinkNames = $ADSiteLinks.Name
$SitesInlcuded = ($ADSiteLinks | Select-Object -ExpandProperty SitesIncluded) -join ' | '
$SiteCost = ($ADSiteLinks | Select-Object -ExpandProperty Cost) -join '<br/>'
$SiteReplicationFreq = ($ADSiteLinks | Select-Object -ExpandProperty ReplicationFrequencyInMinutes) -join '<br/>'
# Create a custom object from the values above and convert it to an html table
$SiteLinkObj = New-Object -TypeName PSObject
$SiteLinkObj | Add-Member -MemberType NoteProperty -Name SiteName -Value $SiteLinkNames
$SiteLinkObj | Add-Member -MemberType NoteProperty -Name SitesIncluded -Value $SitesInlcuded
$SiteLinkObj | Add-Member -MemberType NoteProperty -Name SiteCost -Value $SiteCost
$SiteLinkObj | Add-Member -MemberType NoteProperty -Name SiteReplicationFreq -Value $SiteReplicationFreq
$SiteLinkObjHTML = $SiteLinkObj | ConvertTo-Html
#endregion
#region GPO Info
######################################
# GPO Information
######################################
$DomainGPOs = Get-GPO -all | Select-Object -Property DomainName,DisplayName,CreationTime,ModificationTime
$GPOInfo = $DomainGPOs | ConvertTo-Html
#endregion
#region Priviledged Account Info
######################################
# Priviledged Account Information
######################################
# Priviledge Group Membership
$DomainAdmins = (Get-ADGroupMember -Identity 'Domain Admins' | Select-Object -ExpandProperty SamAccountName) -join '<br/>'
$EnterpriseAdmins = (Get-ADGroupMember -Identity 'Enterprise Admins' | Select-Object -ExpandProperty SamAccountName) -join '<br/>'
$SchemaAdmins = (Get-ADGroupMember -Identity 'Schema Admins' | Select-Object -ExpandProperty SamAccountName) -join '<br/>'
#endregion
#region Exchange Info
######################################
# Exchange Information
######################################
# Get all Org Management Users
$OrgManagement = (Get-ADGroupMember -Identity 'Organization Management' | Select-Object -ExpandProperty SamAccountName) -join '<br/>'
# Get all Exchange Servers
$ExchangeSVRs = (Get-ADGroupMember -Identity 'Exchange Servers' | Select-Object -ExpandProperty SamAccountName) -join '<br/>'
#endregion
#region User Info
######################################
# User Information
######################################
# Users with Passwords set to never expire
$NeverExpire = (Get-ADUser -Filter {PasswordNeverExpires -eq $true} | Select-Object -ExpandProperty SamAccountName) -join '<br/>'
#endregion
#region HTML Output
######################################
# HTML Output
######################################
$Create_HTML_doc = "<!DOCTYPE html>
<head>
<title>Active Directory Information</title>
<style>
BODY{
font-family: Arial, Verdana;
background-color:#D8D8D8;
}
TABLE{
border=1;
border-color:black;
border-width:1px;
border-style:solid;
border-collapse: collapse;
empty-cells:show
}
TH{
font-size: 15px;
border-width:1px;
padding:5px;
border-style:solid;
font-weight:bold;
text-align:left;
border-color:black;
background-color:#ffffff;
empty-cells:show
}
TD{
font-size: 12px;
color:black;
colspan=1;
border-width:1px;
padding:5px;
font-weight:normal;
border-style:solid;
border-color:black;
background-color:#ffffff;
vertical-align: top;
empty-cells:show
}
h1{
font-size: 35px;
}
h2{
font-size: 30px;
text-decoration: underline;
}
h3{
font-size: 15px;
}
</style>
</head>
<h1> Active Directory Information for : $DNSRoot </h1>
<h2> Forest Information </h2>
$ForestOutputObjHTML
<br/>
<h2> Domain Information </h2>
$DomainOutputObjHTML
<br/>
<h2> FSMO Information </h2>
<table>
<tr>
<td><h3>Forest FSMO Roles</h3></td>
<td><h3>Domain FSMO Roles</h3></td>
</tr>
<tr>
<td>$ForestFSMO</td>
<td>$DomainFSMO</td>
</tr>
</table>
<h2> Domain Controller Information </h2>
$DCOutputObjHTML
<br/>
<h2> DNS Information </h2>
<table>
<tr>
<td><h3>Primary Zones</h3></td>
<td><h3>NS Records</h3></td>
<td><h3>MX Records</h3></td>
<td><h3>Forwarders</h3></td>
<td><h3>Scavenging Enabled?</h3></td>
<td><h3>Aging Enabled?</h3></td>
</tr>
<tr>
<td>$PrimaryZones</td>
<td>$NSRecords</td>
<td>$MXRecords</td>
<td>$DNSForwarders</td>
<td>$DNSScavenging</td>
<td>$DNSAging</td>
</tr>
</table>
<h2> DHCP Information </h2>
$DHCPOutputObjHTML
<h2> AD Site Information </h2>
<table>
<tr>
<td><h3>Forest Wide Sites</h3></td>
<td><h3>Site Links</h3></td>
</tr>
<tr>
<td>$Sites</td>
<td>$SiteLinkObjHTML</td>
</tr>
</table>
<h2> GPO Information </h2>
$GPOInfo
<h2>Priviledged Accounts</h2>
<table>
<tr>
<td><h3>Enterprise Admin Group Members</h3></td>
<td><h3>Domain Admin Group Members</h3></td>
<td><h3>Schema Admin Group Members</h3></td>
<td><h3>Password Never Expire</h3></td>
</tr>
<tr>
<td>$EnterpriseAdmins</td>
<td>$DomainAdmins</td>
<td>$SchemaAdmins</td>
<td>$NeverExpire</td>
</tr>
</table>
<h2>Exchange Information</h2>
<table>
<tr>
<td><h3>Organization Management Group Members</h3></td>
<td><h3>Exchange Servers</h3></td>
</tr>
<tr>
<td>$OrgManagement</td>
<td>$ExchangeSVRs</td>
</tr>
</table>
"
$Create_HTML_doc > $File
#endregion
# This is optional, it just opens the html file after the script runs
Invoke-Item -Path $File