-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathADxRay.ps1
More file actions
3885 lines (3209 loc) · 311 KB
/
ADxRay.ps1
File metadata and controls
3885 lines (3209 loc) · 311 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
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#requires -version 2
<#
.SYNOPSIS
Active Directory xRay Inventory
.DESCRIPTION
This Script is based and inspired on Sukhija Vika's 'Active Directory Health Check' script
(https://gallery.technet.microsoft.com/scriptcenter/Active-Directory-Health-709336cd), the amazing Clint Huffman's 'Performance Analysis of Logs (PAL) tool'
(https://github.com/clinthuffman/PAL) and Microsoft's Ned Pyle blogpost 'What does DCDIAG actually... do?'
https://blogs.technet.microsoft.com/askds/2011/03/22/what-does-dcdiag-actually-do/
.OUTPUTS
Details regarding the environment will be presented during the execution of the script. The log file will be created at: C:\AdxRay\ADXRay.log
.NOTES
Version: 6.0.6
Author: Claudio Merola
Co-Author: Raphaela Pereira
Date: 02/28/2024
#>
#---------------------------------------------------------[First Variables]--------------------------------------------------------
param ($Clear,$JobTimeout=180)
Write-Host 'Starting ADxRay Script..' -ForegroundColor Green
# Version
$Global:Ver = '6.0'
$Global:SupBuilds = '10.0 (19044)','10.0 (19045)'
$Global:Runtime = Measure-Command -Expression {
if ((Test-Path -Path C:\ADxRay -PathType Container) -eq $false) {New-Item -Type Directory -Force -Path C:\ADxRay}
$Global:report = ("C:\ADxRay\ADxRay_Report_"+(get-date -Format 'yyyy-MM-dd-hh-mm')+".htm")
if ((test-path $report) -eq $false) {new-item $report -Type file -Force}
Clear-Content $report
$Global:ADxRayLog = "C:\ADxRay\ADxRay.log"
if ((test-path $ADxRayLog) -eq $false) {new-item $ADxRayLog -Type file -Force}
Clear-Content $ADxRayLog
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting ADxRay Script")
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting Data Catcher")
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Setting Error Action Preference")
$ErrorActionPreference = "silentlycontinue"
$TableErrorColor = '#FF5A33'
$TableMeadiumColor = '#FFEC5C'
$TableSuccessColor = '#B4CF66'
$TableFontOnError = '#FFFFFF'
#--------------------------------------------------------------------------------[Begin of Functions]-------------------------------------------------------------------------
#-----------------------------------------[Header]--------------------------------------------------------
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Selecting Script Option")
Write-Host ""
Write-Host "Select the desired option below:"
Write-Host ""
Write-Host "1) " -NoNewline -ForegroundColor Magenta
Write-Host "Full Inventory" -ForegroundColor Yellow
Write-Host "2) " -NoNewline -ForegroundColor Magenta
Write-Host "Soft Inventory" -ForegroundColor Yellow
Write-Host "3) " -NoNewline -ForegroundColor Magenta
Write-Host "Forest Inventory" -ForegroundColor Yellow
Write-Host "4) " -NoNewline -ForegroundColor Magenta
Write-Host "Domain Inventory" -ForegroundColor Yellow
Write-Host "5) " -NoNewline -ForegroundColor Magenta
Write-Host "Only Collect Inventory Files" -ForegroundColor Yellow
Write-Host "6) " -NoNewline -ForegroundColor Magenta
Write-Host "Process Collected Inventory Files" -ForegroundColor Yellow
Write-Host ""
[int]$Global:Option = read-host "( default 1 )"
if($Global:Option -eq 0){$Global:Option = 1}
Write-Host ""
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Option: "+$Global:Option+" Selected")
#----------------------------------------[Begin of Hammer]---------------------------------------------------
function Hammer
{
Write-Host 'Starting The Hammer..'
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting The Hammer!")
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Creating Hammer Folder")
if ((Test-Path -Path C:\ADxRay\Hammer -PathType Container) -eq $false) {New-Item -Type Directory -Force -Path C:\ADxRay\Hammer}
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Cleaning current Powershell Job History")
Get-Job | Remove-Job
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Calling DCDiag")
if($Clear.isPresent)
{
$Files = Get-ChildItem -path 'C:\ADxRay\Hammer\'
Foreach ($File in $Files)
{
remove-item -Path $File.FullName -Force
}
}
function HammerForest
{
Write-Progress -activity 'Running Inventories' -Status "1% Complete." -CurrentOperation 'Triggering Forest Inventory..'
Start-job -Name 'Diag' -scriptblock {dcdiag /e /s:$($args)} -ArgumentList $Forest.SchemaRoleOwner.Name | Out-Null
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting Active Directory RecycleBin Check")
Start-job -Name 'RecycleBin' -ScriptBlock {if ((Get-ADOptionalFeature -Filter * | Where-Object {$_.Name -eq 'Recycle Bin Feature' -and $_.EnabledScopes -ne '' })) {'Enabled'}else{'Not Enabled'}} | Out-Null
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Duplicated SPNs check")
Start-job -Name 'SPN' -scriptblock {setspn -X -F} | Out-Null
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting Trusts Inventory")
Start-job -Name 'Trusts' -scriptblock {Get-ADtrust -Filter * -Server $($args) -ErrorAction SilentlyContinue -WarningAction SilentlyContinue } -ArgumentList $Forest.SchemaRoleOwner.Name | Out-Null
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting Domain Inventory")
Write-Progress -activity 'Running Inventories' -Status "5% Complete." -CurrentOperation 'Triggering Domain Inventory..'
$Global:SecGroups = @('Domain Admins','Schema Admins','Enterprise Admins','Server Operators','Account Operators','Administrators','Backup Operators','Print Operators','Domain Controllers','Read-only Domain Controllers','Group Policy Creator Owners','Cryptographic Operators','Distributed COM Users')
Foreach ($zone in $Forest.ApplicationPartitions.Name)
{
Start-job -Name ('Zone_'+$zone) -scriptblock {Get-ADObject -Filter {Name -like '*..InProgress*'} -SearchBase $($args)} -ArgumentList $zone
}
}
function HammerDomain
{
Foreach ($Domain in $Global:Domains)
{
start-job -Name ($Domain.Name+'_Inv') -scriptblock {Get-ADDomain -Identity $($args) -ErrorAction SilentlyContinue -WarningAction SilentlyContinue} -ArgumentList $Domain.Name | Out-Null
start-job -Name ($Domain.Name+'_RODC') -scriptblock {Get-ADDomainController -Filter {IsReadOnly -eq $true}} -ArgumentList $Domain.Name | Out-Null
start-job -Name ($Domain.Name+'_SysVol') -scriptblock {Get-ChildItem -path $($args) -Recurse | Where-Object -FilterScript {$_.PSIsContainer -eq $false} | Group-Object -Property Extension | ForEach-Object -Process {
New-Object -TypeName PSObject -Property @{
'Extension'= $_.name
'Count' = $_.count
'TotalSize (MB)'= '{0:N2}' -f ((($_.group | Measure-Object length -Sum).Sum) /1MB)
'TotalSize' = (($_.group | Measure-Object length -Sum).Sum)
} } | Sort-Object -Descending -Property 'Totalsize'} -ArgumentList ('\\'+$Domain.Name+'\SYSVOL\'+$Domain.Name) | Out-Null
start-job -Name ($Domain.Name+'_GPOs') -scriptblock {Get-GPOReport -All -ReportType XML -Path ("C:\ADxRay\Hammer\GPOs_"+$args+".xml")} -ArgumentList $Domain.Name | Out-Null
start-job -Name ($Domain.name+'_Usrs') -scriptblock {dsquery * -filter sAMAccountType=805306368 -s $($args) -attr userAccountControl -limit 0} -ArgumentList $Domain.PdcRoleOwner.Name | Out-Null
start-job -Name ($Domain.name+'_Comps') -scriptblock {dsquery * -filter sAMAccountType=805306369 -s $($args) -Attr OperatingSystem -limit 0} -ArgumentList $Domain.PdcRoleOwner.Name | Out-Null
start-job -Name ($Domain.name+'_GrpAll') -scriptblock {ForEach($grp in $($args[1])) {@{$grp = ((dsquery * -filter "(&(objectclass=group)(name=$grp))" -s $($args[0]) -attr member -limit 0).split(";") | Where-Object {$_ -like '*DC*'}).count}}} -ArgumentList $Domain.PdcRoleOwner.Name,$SecGroups | Out-Null
}
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting Domain Controllers Inventory")
}
function HammerDC
{
Write-Progress -activity 'Running Inventories' -Status "10% Complete." -CurrentOperation 'Triggering Domain Controller Inventory..'
Foreach ($DC in $Global:DCs) {
#start-job -Name ($DC.Name+'_Evts') -scriptblock {(Get-EventLog -ComputerName $args -LogName Security -InstanceId 4618,4649,4719,4765,4766,4794,4897,4964,5124,1102).Count} -ArgumentList $DC.Name | Out-Null
#start-job -Name ($DC.Name+'_EvtBackup') -scriptblock {Get-winevent -Filterhashtable @{logname='Microsoft-Windows-Backup/operational';ID=4} -ComputerName $($args[0])} -ArgumentList $DC.Name | Out-Null
#start-job -Name ($DC.Name+'_BatchJobEvt') -scriptblock {(Get-EventLog -LogName Security -InstanceId 4624 -Message '*Logon Type: 4*' -ComputerName $args).Count} -ArgumentList $DC.Name | Out-Null
#start-job -Name ($DC.Name+'_CleartxtEvt') -scriptblock {(Get-EventLog -LogName Security -InstanceId 4624 -Message '*Logon Type: 8*' -ComputerName $args).Count} -ArgumentList $DC.Name | Out-Null
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting Domain Controllers Inventory of: "+$DC.Name+'. On: '+$DC.Domain)
Start-job -Name ('Inv_'+$DC.Name) -ScriptBlock {
$job = @()
$Inv = ([PowerShell]::Create()).AddScript({param($DomControl)Get-ADDomainController -Server $DomControl}).AddArgument($($args[0]))
$Software64 = ([PowerShell]::Create()).AddScript({param($DomControl)Invoke-Command -cn $DomControl -ScriptBlock {Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*}}).AddArgument($($args[0]))
$Software86 = ([PowerShell]::Create()).AddScript({param($DomControl)Invoke-Command -cn $DomControl -ScriptBlock {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*}}).AddArgument($($args[0]))
$Feature = ([PowerShell]::Create()).AddScript({param($DomControl)Invoke-Command -cn $DomControl -ScriptBlock {Get-SmbServerConfiguration | Select EnableSMB1Protocol}}).AddArgument($($args[0]))
$HW = ([PowerShell]::Create()).AddScript({param($DomControl)Invoke-Command -cn $DomControl -ScriptBlock {systeminfo /fo CSV | ConvertFrom-Csv}}).AddArgument($($args[0]))
$HWBkp = ([PowerShell]::Create()).AddScript({param($DomControl)systeminfo /S $DomControl /fo CSV | ConvertFrom-Csv}).AddArgument($($args[0]))
$Backup = ([PowerShell]::Create()).AddScript({param($DomControl)repadmin /showbackup $DomControl}).AddArgument($($args[0]))
$NTP1 = ([PowerShell]::Create()).AddScript({param($DomControl)Invoke-Command -cn $DomControl -ScriptBlock {W32TM /query /status}}).AddArgument($($args[0]))
$NTP2 = ([PowerShell]::Create()).AddScript({param($DomControl)Invoke-Command -cn $DomControl -ScriptBlock {W32TM /query /configuration}}).AddArgument($($args[0]))
$HotFix = ([PowerShell]::Create()).AddScript({param($DomControl)Get-HotFix -ComputerName $DomControl | Sort-Object { [datetime]$_.InstalledOn },HotFixID -desc | Select-Object -First 1}).AddArgument($($args[0]))
$Proc = ([PowerShell]::Create()).AddScript({param($DomControl)(Get-CimInstance -Class Win32_ComputerSystem -ComputerName $DomControl).NumberOfLogicalProcessors}).AddArgument($($args[0]))
$FreeSpace = ([PowerShell]::Create()).AddScript({param($DomControl)(Get-Counter -counter "\LogicalDisk(*)\% Free Space" -ComputerName $DomControl).CounterSamples}).AddArgument($($args[0]))
$Spooler = ([PowerShell]::Create()).AddScript({param($DomControl)Get-CimInstance -ClassName Win32_Service -Filter "Name = 'Spooler'" -Property State,StartMode -ComputerName $DomControl}).AddArgument($($args[0]))
$GPResult = ([PowerShell]::Create()).AddScript({param($DomControl)Get-GPResultantSetOfPolicy -Computer $DomControl -ReportType Xml -Path ("C:\ADxRay\Hammer\RSOP_"+$DomControl+".xml")}).AddArgument($($args[0]))
$DNS = ([PowerShell]::Create()).AddScript({param($DomControl)Get-DnsServer -ComputerName $DomControl}).AddArgument($($args[0]))
$ldapRR = ([PowerShell]::Create()).AddScript({param($DomControl,$Dom)Get-DnsServerResourceRecord -ZoneName ('_msdcs.'+$Dom) -Name '_ldap._tcp.dc' -ComputerName $DomControl}).AddArgument($($args[0])).AddArgument($($args[1]))
$jobInv = $Inv.BeginInvoke()
$jobSW64 = $Software64.BeginInvoke()
$jobSW86 = $Software86.BeginInvoke()
$jobFeature = $Feature.BeginInvoke()
$jobHW = $HW.BeginInvoke()
$jobHWBkp = $HWBkp.BeginInvoke()
$jobBackup = $Backup.BeginInvoke()
$jobNTP1 = $NTP1.BeginInvoke()
$jobNTP2 = $NTP2.BeginInvoke()
$JobHotFix = $HotFix.BeginInvoke()
$jobProc = $Proc.BeginInvoke()
$jobFreeSpace = $FreeSpace.BeginInvoke()
$jobSpooler = $Spooler.BeginInvoke()
$jobGPResult = $GPResult.BeginInvoke()
$jobDNS = $DNS.BeginInvoke()
$jobLdapRR = $ldapRR.BeginInvoke()
$job += $jobInv
$job += $jobSW64
$job += $jobSW86
$job += $jobFeature
$job += $jobHW
$job += $jobHWBkp
$job += $jobBackup
$job += $jobNTP1
$job += $jobNTP2
$job += $JobHotFix
$job += $jobProc
$job += $jobFreeSpace
$job += $jobSpooler
$job += $jobGPResult
$job += $jobDNS
$job += $jobLdapRR
while ($Job.Runspace.IsCompleted -contains $false) {}
$InvS = $Inv.EndInvoke($jobInv)
$SW64S = $Software64.EndInvoke($jobSW64)
$SW86S = $Software86.EndInvoke($jobSW86)
$FeatureS = $Feature.EndInvoke($jobFeature)
$HWS = $HW.EndInvoke($jobHW)
$HWSBkp = $HWBkp.EndInvoke($jobHWBkp)
$BackupS = $Backup.EndInvoke($jobBackup)
$NTP1S = $NTP1.EndInvoke($jobNTP1)
$NTP2S = $NTP2.EndInvoke($jobNTP2)
$HotFixS = $HotFix.EndInvoke($jobHotFix)
$ProcS = $Proc.EndInvoke($jobProc)
$FreeSpaceS = $FreeSpace.EndInvoke($jobFreeSpace)
$SpoolerS = $Spooler.EndInvoke($jobSpooler)
$DNSS = $DNS.EndInvoke($jobDNS)
$ldapRRS = $ldapRR.EndInvoke($jobLdapRR)
$Inv.Dispose()
$Software64.Dispose()
$Software86.Dispose()
$Feature.Dispose()
$HW.Dispose()
$HWBkp.Dispose()
$Backup.Dispose()
$NTP1.Dispose()
$NTP2.Dispose()
$HotFix.Dispose()
$Proc.Dispose()
$FreeSpace.Dispose()
$Spooler.Dispose()
$GPResult.Dispose()
$DNS.Dispose()
$ldapRR.Dispose()
$DataServer = @{
'Inventory' = $InvS;
'Software_64' = $SW64S;
'Software_86' = $SW86S;
'Installed_Features' = $FeatureS;
'Hardware' = $HWS;
'HardwareBkp' = $HWSBkp;
'Backup' = $BackupS;
'NTP_Status' = $NTP1S;
'NTP_Config' = $NTP2S;
'HotFix' = $HotFixS;
'Processor' = $ProcS;
'FreeSpace' = $FreeSpaceS;
'Spooler' = $SpoolerS;
'DNS' = $DNSS;
'ldapRR' = $ldapRRS}
$DataServer
} -ArgumentList $DC.Name,$DC.Domain
}
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Waiting Inventories Conclusion")
}
function WaitJobs
{
$c = 0
$WaitTime = get-date
$WaitTime2 = get-date
while (get-job | Where-Object {$_.State -eq 'Running'})
{
$jb = get-job
$c = (((($jb.count - ($jb | Where-Object {$_.State -eq 'Running'}).Count)) / $jb.Count) * 100)
$c = [math]::Round($c)
Write-Progress -activity 'Running Inventories' -Status "$c% Complete." -PercentComplete $c -CurrentOperation 'Waiting Inventories..'
if ((New-TimeSpan -Start $WaitTime2 -End (get-date)).TotalMinutes -ge 10)
{
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Warn - Still Waiting for the following Inventory Jobs:")
foreach($jbb in ($jb | Where-Object {$_.State -eq 'Running'}))
{
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Warn - Job: "+$jbb.Name)
}
$WaitTime2 = get-date
}
if ((New-TimeSpan -Start $WaitTime -End (get-date)).TotalMinutes -ge $JobTimeout)
{
Get-Job | Stop-Job | Out-Null
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Err - Timing Out Inventory Jobs")
}
Start-Sleep -Seconds 2
}
Write-Progress -activity 'Running Inventories' -Status "100% Complete." -Completed
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - All Inventories are completed")
}
function ForestJob
{
Write-Host 'Inventories done..'
Write-Host 'Starting to Process the Results..'
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting to Process Forest Inventory")
$DuplicatedZones = @()
$Global:Diag = Receive-Job -Name 'Diag' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$RecycleBin = Receive-Job -Name 'RecycleBin' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$SPN = Receive-Job -Name 'SPN' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$Trusts = Receive-Job -Name 'Trusts' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
Foreach ($zone in $Forest.ApplicationPartitions.Name)
{
$DuplicatedZones += receive-job -Name ('Zone_'+$zone)
}
if ((test-path 'C:\ADxRay\Hammer\Forest.xml') -eq $true) {remove-item -Path 'C:\ADxRay\Hammer\Forest.xml' -Force}
$Trss = @()
Foreach ($Trust in $Trusts)
{
$Trss += $Trust
}
$SSPN = ($SPN | Select-String -Pattern ('duplicate SPNs')).ToString()
$Fores = @{
'ForestName' = $Forest.Name;
'Domains' = $Forest.Domains.Name;
'RecycleBin' = $RecycleBin;
'ForestMode' = $Forest.ForestMode;
'GlobalCatalogs' = $Forest.GlobalCatalogs.Name;
'Sites' = $Forest.Sites.Name;
'Trusts' = $Trss;
'SPN' = $SSPN;
'DuplicatedDNSZones' = $DuplicatedZones.DistinguishedName
}
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Registering Forest XML File")
$Fores | Export-Clixml -Path 'C:\ADxRay\Hammer\Forest.xml'
}
function DomainJob
{
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting to Process Domain Inventory")
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting to Process Domains Details")
Foreach ($Domain in $Global:Domains)
{
$InvDom = Receive-Job -Name ($Domain.Name+'_Inv') -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$InvRODC = Receive-Job -Name ($Domain.Name+'_RODC') -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$SysVolDom = Receive-Job -Name ($Domain.Name+'_SysVol') -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$Usrs = Receive-Job -Name ($Domain.name+'_Usrs') -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$Comps = Receive-Job -Name ($Domain.name+'_Comps') -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$GrpAll = Receive-Job -Name ($Domain.name+'_GrpAll') -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$GPOALL = Receive-Job -Name ($Domain.name+'_GPOs') -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
Start-job -Name ($Domain.Name+'_job') -ScriptBlock {
if((test-path ('C:\ADxRay\Hammer\Domain_'+$($args[0]).Name+'.xml')) -eq $true -and $($args[9]) -ne 2)
{
remove-item -Path ('C:\ADxRay\Hammer\Domain_'+$($args[0]).Name+'.xml') -Force
}
$InvDom = $($args[2])
$SysVolDom = $($args[3])
$Usrs = $($args[4])
$Comps = $($args[5])
$GrpAll = $($args[6])
$GPOALL = $($args[7])
$RODC = $($args[8])
$att = @()
foreach ($UAC in $Usrs)
{
$att += 1..26 | Where-Object {$UAC -bAnd [math]::Pow(2,$_)}
}
$DomainTable = @{
'Domain' = $($args[0]).name;
'DNSRoot' = $InvDom.DNSRoot;
'ParentDomain' = $InvDom.ParentDomain;
'ChildDomains' = $InvDom.ChildDomains;
'DomainMode' = $InvDom.DomainMode;
'ComputersContainer' = $InvDom.ComputersContainer;
'UsersContainer' = $InvDom.UsersContainer;
'DCCount' = ($($args[1]) | Where-Object {$_.Name -eq $InvDom.DNSRoot}).DomainControllers.Count;
'SysVolContent' = $SysVolDom;
'Users' = $att | Group-Object;
'RODC' = $RODC.HostName;
'Computers' = $Comps;
'AdminGroups'=$GrpAll | Where-Object {$_.Keys -in ('Domain Admins','Schema Admins','Enterprise Admins','Server Operators','Account Operators','Administrators','Backup Operators','Print Operators','Domain Controllers','Read-only Domain Controllers','Group Policy Creator Owners','Cryptographic Operators','Distributed COM Users')};
'Groups'=$GrpAll | Sort-Object Values,Keys -desc | Select-Object -First 10;
'SmallGroups' = ($GrpAll | Sort-Object Values | Group-Object Values | Select-Object -Index 0,1 | Measure-Object -Property Count -Sum).Sum
}
$DomainTable | Export-Clixml -Path ('C:\ADxRay\Hammer\Domain_'+$($args[0]).Name+'.xml')
} -ArgumentList $Domain,$Forest.domains,$InvDom,$SysVolDom,$Usrs,$Comps,$GrpAll,$GPOALL,$InvRODC,$Global:Option
}
}
function DCjob
{
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting to Process Domain Controllers Inventory")
Foreach ($DC in $Global:DCs)
{
Remove-Variable Inv1
$Inv1 = Receive-Job -Name ('Inv_'+$DC.Name) -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
Start-job -Name ('Job_'+$DC.Name) -ScriptBlock {
if((test-path ("C:\ADxRay\Hammer\Inv_"+$($args[0]).Name+".xml")) -eq $true -and $($args[3]) -ne 2)
{
remove-item -Path ("C:\ADxRay\Hammer\Inv_"+$($args[0]).Name+".xml") -Force
}
$Inv1 = $($args[1])
$TotalMem = if([string]::IsNullOrEmpty($Inv1.Hardware.'Total Physical Memory')){$Inv1.HardwareBkp.'Total Physical Memory'}Else{$Inv1.Hardware.'Total Physical Memory'}
$BootTime = if([string]::IsNullOrEmpty($Inv1.Hardware.'System Boot Time')){$Inv1.HardwareBkp.'System Boot Time'}Else{$Inv1.Hardware.'System Boot Time'}
$InstallDate = if([string]::IsNullOrEmpty($Inv1.Hardware.'Original Install Date')){$Inv1.HardwareBkp.'Original Install Date'}Else{$Inv1.Hardware.'Original Install Date'}
$BiosVer = if([string]::IsNullOrEmpty($Inv1.Hardware.'BIOS Version')){$Inv1.HardwareBkp.'BIOS Version'}Else{$Inv1.Hardware.'BIOS Version'}
$DomControl = @{
'Domain' = $Inv1.Inventory.Domain;
'Hostname' = $Inv1.Inventory.Hostname;
'IPv4Address' = $Inv1.Inventory.IPv4Address;
'IsGlobalCatalog' = $Inv1.Inventory.IsGlobalCatalog;
'OperatingSystem' = $Inv1.Inventory.OperatingSystem;
'OperatingSystemVersion' = $Inv1.Inventory.OperatingSystemVersion;
'OperationMasterRoles' = $Inv1.Inventory.OperationMasterRoles;
'Site' = $Inv1.Inventory.Site;
'Backup' = $Inv1.Backup;
'HW_Mem' = $TotalMem;
'HW_Boot' = $BootTime;
'HW_Install' = $InstallDate;
'HW_BIOS' = $BiosVer;
'HotFix' = $Inv1.HotFix;
'NTPStatus' = $Inv1.NTP_Status;
'NTPConf' = $Inv1.NTP_Config;
'HW_LogicalProc' = $Inv1.Processor;
'HW_FreeSpace' = $Inv1.FreeSpace;
'Spooler_State' = $Inv1.Spooler.State;
'Spooler_StartMode' = $Inv1.Spooler.StartMode;
'DNS' = $Inv1.DNS;
'ldapRR' = $Inv1.ldapRR;
'DCDiag' = $($args[2]) | Select-String -Pattern ($($args[0]).Name.Split('.')[0]);
'InstalledFeatures' = $Inv1.Installed_Features;
'InstalledSoftwaresx64' = $Inv1.Software_64 | Where-Object {$_.DisplayName} | Select-Object DisplayName, DisplayVersion, Publisher;
'InstalledSoftwaresx86' = $Inv1.Software_86 | Where-Object {$_.DisplayName} | Select-Object DisplayName, DisplayVersion, Publisher
}
$DomControl | Export-Clixml -Path ('C:\ADxRay\Hammer\Inv_'+$($args[0]).Name+'.xml')
} -ArgumentList $DC,$Inv1,$Diag,$Global:Option
}
}
function WaitJobs2
{
$c = 0
$WaitTime = get-date
$WaitTime2 = get-date
while (get-job | Where-Object {$_.State -eq 'Running'})
{
$jb = get-job
$c = (((($jb.count - ($jb | Where-Object {$_.State -eq 'Running'}).Count)) / $jb.Count) * 100)
$c = [math]::Round($c)
Write-Progress -activity 'Processing Inventories' -Status "$c% Complete." -PercentComplete $c -CurrentOperation 'Waiting Processing Jobs..'
if ((New-TimeSpan -Start $WaitTime2 -End (get-date)).TotalMinutes -ge 10)
{
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Warn - Still Waiting for the following Processing Jobs:")
foreach($jbb in ($jb | Where-Object {$_.State -eq 'Running'}))
{
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Warn - Job: "+$jbb.Name)
}
$WaitTime2 = get-date
}
if ((New-TimeSpan -Start $WaitTime -End (get-date)).TotalMinutes -ge $JobTimeout)
{
Get-Job | Stop-Job | Out-Null
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Err - Timing Out Inventory Jobs")
}
Start-Sleep -Seconds 2
}
Write-Progress -activity 'Running Inventories' -Status "100% Complete." -Completed
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - All Inventories are completed")
}
if($Global:Option -eq 1 -or $Global:Option -eq 2)
{
HammerForest
HammerDomain
HammerDC
}
elseif($Global:Option -eq 3)
{
HammerForest
}
elseif($Global:Option -eq 4)
{
HammerForest
HammerDomain
}
WaitJobs
if($Global:Option -eq 1 -or $Global:Option -eq 2)
{
ForestJob
DomainJob
DCjob
}
elseif($Global:Option -eq 3)
{
ForestJob
}
elseif($Global:Option -eq 4)
{
ForestJob
DomainJob
}
WaitJobs2
$jbs = Get-Job
foreach ($JB in $jbs){
$JbName = $jb.Name
$jbcmd = $jb.command
if ($JB.State -eq 'Failed')
{
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - The following Inventory Job Failed: "+$jbName)
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - With the following Command Line: "+$jbcmd)
}
$time = New-TimeSpan -Start $JB.PSBeginTime -End $JB.PSEndTime
$TimeJobMin = $time.TotalMinutes.ToString('#######.##')
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - The following Inventory Job: "+$jbName+'. run time was: '+$TimeJobMin+' Minutes.')
}
Write-Host ('End of Hammer phase. ') -NoNewline
Write-Host ($jbs | Where-Object {$_.State -eq 'Completed'}).Count -NoNewline -ForegroundColor Magenta
Write-Host ' Inventory jobs completed and ' -NoNewline
Write-Host ($jbs | Where-Object {$_.State -eq 'Failed'}).Count -NoNewline -ForegroundColor Red
Write-Host ' Inventory jobs failed..'
$DomainControllersFolder = Get-ChildItem -Path 'C:\ADxRay\Hammer\' -Recurse
$DomainControllersInv = $DomainControllersFolder | Where-Object {$_.Name -like 'inv_*'}
$DomainControllersRSOP = $DomainControllersFolder | Where-Object {$_.Name -like 'RSOP_*'}
$DCsInv = @()
foreach($DC in $DomainControllersInv)
{
$DCsInv += $DC.Name.replace('Inv_','').replace('.xml','')
}
$DCsRSOP = @()
foreach($DC in $DomainControllersRSOP)
{
$DCsRSOP += $DC.Name.replace('RSOP_','').replace('.xml','')
}
foreach($DC in $Global:DCs)
{
if($DC -notin $DCsInv)
{
Write-Host 'General Inventory ' -NoNewline
Write-Host 'Failed' -ForegroundColor Red -NoNewline
Write-Host 'for: ' -NoNewline
Write-Host $TempDC -ForegroundColor Blue
}
if($DC -notin $DCsRSOP)
{
Write-Host 'RSOP Inventory ' -NoNewline
Write-Host 'Failed' -ForegroundColor Red -NoNewline
Write-Host 'for: ' -NoNewline
Write-Host $DC -ForegroundColor Blue
}
}
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - End of Hammer")
Get-Job | Remove-Job
}
#-----------------------------------------[End of Hammer]---------------------------------------------------
#----------------------------------------[Begin of Report]---------------------------------------------------
function Report {
Add-Content $report "<html>"
Add-Content $report " <head>"
Add-Content $report " <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"
Add-Content $report " <title>ADxRay - $Forest</title>"
Add-Content $report ' <STYLE TYPE="text/css">'
Add-Content $report " <!-- -->"
Add-Content $report " body {"
Add-Content $report " font: normal 8pt/16pt Verdana;"
Add-Content $report " color: #000000;"
Add-Content $report " margin-left: 50px;"
Add-Content $report " margin-top: 80px;"
Add-Content $report " margin-right: 50px;"
Add-Content $report " margin-bottom: 10px;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " h1 {"
Add-Content $report " background-color: #44803F;"
Add-Content $report " font-size: 62px;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " text-align: center;"
Add-Content $report " width: 100%;"
Add-Content $report " line-height: 150px;"
Add-Content $report " height: 150px;"
Add-Content $report " margin: 0;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .title {"
Add-Content $report " color: #FFFFFF;"
Add-Content $report " font-size: 65px;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " font-weight: normal;"
Add-Content $report " text-decoration: none;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .tablink {"
Add-Content $report " background-color: #555;"
Add-Content $report " color: white;"
Add-Content $report " float: left;"
Add-Content $report " border: none;"
Add-Content $report " outline: none;"
Add-Content $report " cursor: pointer;"
Add-Content $report " padding: 14px 16px;"
Add-Content $report " font-size: 17px;"
Add-Content $report " width: 20%;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .tablink:hover {"
Add-Content $report " background-color: #777;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .tabcontent {"
Add-Content $report " color: black;"
Add-Content $report " display: none;"
Add-Content $report " padding: 0 20px;"
Add-Content $report " height: 100%;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .note {"
Add-Content $report " color: #000000;"
Add-Content $report " font-size: 12px;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " text-align: left;"
Add-Content $report " margin-top: 0;"
Add-Content $report " margin-bottom: 0;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " h2 {"
Add-Content $report " color: #000000;"
Add-Content $report " font-size: 52px;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " text-align: center;"
Add-Content $report " font-weight: normal;"
Add-Content $report " margin-top: 0;"
Add-Content $report " margin-bottom: 0;"
Add-Content $report " padding: 100px 0 0 0;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " h3 {"
Add-Content $report " color: #000000;"
Add-Content $report " font-size: 24px;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " text-align: center;"
Add-Content $report " font-weight: normal;"
Add-Content $report " margin-top: 0;"
Add-Content $report " margin-bottom: 0;"
Add-Content $report " padding: 100px 0 0 0;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .vertical-table {"
Add-Content $report " border: hidden;"
Add-Content $report " border-radius: 15px;"
Add-Content $report " margin: 60px auto;"
Add-Content $report " width: 50%;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .vertical-table > tbody > tr > th {"
Add-Content $report " border: 1px solid rgba(0, 0, 0, 0.433);"
Add-Content $report " width: 30%;"
Add-Content $report " background-color: #146152;"
Add-Content $report " color: white;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " font-size: 16px;"
Add-Content $report " letter-spacing: 2%;"
Add-Content $report " height: 70px;"
Add-Content $report " text-align: center;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .vertical-table > tbody > tr > td {"
Add-Content $report " border: 1px solid rgba(0, 0, 0, 0.433);"
Add-Content $report " width: 50%;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " font-size: 14px;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " footer {"
Add-Content $report " padding-top: 90px;"
Add-Content $report " padding-bottom: 30px"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .back-button {"
Add-Content $report " font-size: 1.1em;"
Add-Content $report " text-decoration: none;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .back-button:visited {"
Add-Content $report " color: blue;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .disclaimer {"
Add-Content $report " margin: 20px 20px 0 0;"
Add-Content $report " border: 1px hidden black;"
Add-Content $report " border-radius: 25px;"
Add-Content $report " padding: 5px 15px;"
Add-Content $report " text-align: left;"
Add-Content $report " background-color: silver;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " p {"
Add-Content $report " color: #000000;"
Add-Content $report " font-size: 12px;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " text-align: center;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " table {"
Add-Content $report " border-collapse: collapse;"
Add-Content $report " border-radius: 25px;"
Add-Content $report " overflow: hidden;"
Add-Content $report " margin: 60px auto;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " tr:nth-child(odd) {"
Add-Content $report " background-color: #eee;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " tr:nth-child(even) {"
Add-Content $report " background-color: #ccc;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " th {"
Add-Content $report " background-color: #146152;"
Add-Content $report " color: white;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " font-size: 16px;"
Add-Content $report " letter-spacing: 2%;"
Add-Content $report " height: 70px;"
Add-Content $report " text-align: center;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " td {"
Add-Content $report " padding: 8px;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " font-size: 13px;"
Add-Content $report " text-align: center;"
Add-Content $report " border: '1';"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " h4 {"
Add-Content $report " color: #000000;"
Add-Content $report " font-size: 16px;"
Add-Content $report " font-family: 'Segoe UI',SegoeUI,'Helvetica Neue',Helvetica,Arial,sans-serif;"
Add-Content $report " text-align: left;"
Add-Content $report " font-weight: normal;"
Add-Content $report " margin-top: 6;"
Add-Content $report " margin-bottom: 6;"
Add-Content $report " padding: 30px 0 0 0;"
Add-Content $report " }"
Add-Content $report ""
Add-Content $report " .hr2 {"
Add-Content $report " width: 33%;"
Add-Content $report " margin-left: 0;"
Add-Content $report " }"
Add-Content $report " </style>"
Add-Content $report " </head>"
Add-Content $report " <body>"
#----------------------------------------------------------------------------------------------[Header]--------------------------------------------------------
Add-Content $report " <header>"
Add-Content $report ""
Add-Content $report " <h1><a class='title' href='https://github.com/ClaudioMerola/ADxRay' target='_blank' rel='external'>Active Directory xRay Report</a></h1>"
$button = @'
<button class="tablink" onclick="openTab('Forest')" id="OpenFirst">Forest</button>
'@
Add-Content $report $button
$button = @'
<button class="tablink" onclick="openTab('Domains')">Domains</button>
'@
Add-Content $report $button
$button = @'
<button class="tablink" onclick="openTab('DomainControllers')">Domain Controllers</button>
'@
Add-Content $report $button
$button = @'
<button class="tablink" onclick="openTab('Security')">Security</button>
'@
Add-Content $report $button
$button = @'
<button class="tablink" onclick="openTab('Inventory')">Hardware / Software</button>
'@
Add-Content $report $button
Add-Content $report " <p class='note'><strong>Version: $Ver</strong></p>"
Add-Content $report " <p class='note'>This Report is intended to help network administrators and contractors to get a better understanding and overview of the actual status and health of theirs Active Directory Forest, Domains, Domain Controllers, DNS Servers and Active Directory objects such as User Accounts, Computer Accounts, Groups and Group Policies. This report has been tested in several Active Directory topologies and environments without further problems or impacts in the servers or environment´s performance. If you however experience some sort of problem while running this script/report. Feel free to send that feedback and I will help to investigate as soon as possible (feedback information’s are presented at the end of this report). Thanks for using.</p>"
Add-Content $report " </header>"
#-----------------------------------------------------------------------------------------------[Forest Header]--------------------------------------------------------
Add-Content $report ""
Add-Content $report " <main>"
Add-Content $report " <div id='Forest' class='tabcontent'>"
Add-Content $report " <section>"
Add-Content $report " <h2>Active Directory Forest<HR></h2>"
Add-Content $report " <p>This section is intended to give an overall view of the <strong>Active Directory Forest</strong>, as so as the <strong>Active Directory Domains</strong> and <strong>Domain Controllers</strong> and configured <strong>Trusts</strong> between Active Directory Domains and others Active Directory Forests.</p>"
Add-Content $report " </section>"
#----------------------------------------------------------------------------------------------[Forest Details]--------------------------------------------------------
Add-Content $ADxRayLog ((get-date -Format 'MM-dd-yyyy HH:mm:ss')+" - Info - Starting Forest Report: "+$Forest)
Try
{
Add-Content $report " <section>"
Add-Content $report " <h3>Active Directory Forest View ($Forest)</h3>"
Add-Content $report " <table width='40%' align='center' border='1' class=vertical-table>"
$Fore = Import-Clixml -Path C:\ADxRay\Hammer\Forest.xml
$ForeName = $Fore.ForestName
Write-Host 'Analyzing and Reporting Forest: ' -NoNewline
Write-Host $ForeName -ForegroundColor Magenta
$Dom = $Fore.Domains
$RecycleBin = $Fore.RecycleBin
$ForeMode = $Fore.ForestMode.Value
$ForeGC = $Fore.GlobalCatalogs
$ForeSites = $Fore.Sites
$SPN = $Fore.SPN
$dupdnsfor = 0
$dupdnsdom = 0
Foreach($dup in $Fore.DuplicatedDNSZones)
{
if ($dup -like '*DC=ForestDnsZones,*') {$dupdnsfor ++}
if ($dup -like '*DC=DomainDnsZones,*') {$dupdnsdom ++}
}
Add-Content $report " <tr>"
Add-Content $report " <th>Forest Name</th>"
Add-Content $report " <td>$ForeName</td>"
Add-Content $report " </tr>"
Add-Content $report " <tr>"
Add-Content $report " <th>Domains</th>"
Add-Content $report " <td>$Dom</td>"
Add-Content $report " </tr>"
Add-Content $report " <tr>"
Add-Content $report " <th title='The Forest functional level is out of support. You should raise the Forest functional level as soon as possible to avoid problems.'>Forest Functional Level</th>"
if ($ForeMode -like '*NT*' -or $ForeMode -like '*2000*' -or $ForeMode -like '*2003*' -or $ForeMode -like '*2008*')
{
Add-Content $report " <td bgcolor=$TableErrorColor align=center><font color=$TableFontOnError>$ForeMode</font></td>"
}
elseif ($ForeMode -like '*2012*')
{
Add-Content $report " <td bgcolor=$TableMeadiumColor align=center>$ForeMode</td>"
}
elseif ($ForeMode -like '*2019*' -or $ForeMode -like '*2016*' -or $ForeMode -like '*2022*')
{
Add-Content $report " <td bgcolor=$TableSuccessColor align=center>$ForeMode</td>"
}
else
{
Add-Content $report " <td>$ForeMode</td>"
}
Add-Content $report " </tr>"
Add-Content $report " <tr>"
Add-Content $report " <th>Global Catalogs</th>"
Add-Content $report " <td>$ForeGC</td>"
Add-Content $report " </tr>"
Add-Content $report " <tr>"
Add-Content $report " <th title='Active Directory's Recyble Bin is very useful tool and is recommended to have it enabled.'>Recycle Bin</th>"
if ($RecycleBin -ne 'Enabled')
{
Add-Content $report " <td bgcolor=$TableErrorColor align=center><font color=$TableFontOnError>$RecycleBin</font></td>"
}
else
{
Add-Content $report " <td bgcolor=$TableSuccessColor align=center>$RecycleBin</td>"
}
Add-Content $report " </tr>"
Add-Content $report " <tr>"
Add-Content $report " <th>Sites</th>"
Add-Content $report " <td>$ForeSites</td>"
Add-Content $report " </tr>"
Add-Content $report " <tr>"
Add-Content $report " <th title='Duplicate SPNs can cause the KDC to generate a service ticket that may be created based on the shared secret of the wrong account. Which will lead to authentication fails'>Duplicate SPN</th>"
if ($SPN -ne 'found 0 group of duplicate SPNs.')
{
Add-Content $report " <td bgcolor=$TableErrorColor><font color=$TableFontOnError>$SPN</font></td>"
}
else
{
Add-Content $report " <td bgcolor=$TableSuccessColor>$SPN</td>"
}
Add-Content $report " </tr>"
Add-Content $report " <tr>"
Add-Content $report " <th title='Active Directory relies heavily in Domain Name System. Duplicate zones can cause numerous issues and should be investigated.'>Duplicated DNS Zones (Forest)</th>"
if ($dupdnsfor -ge 1)
{
Add-Content $report " <td bgcolor=$TableErrorColor align=center><font color=$TableFontOnError>$dupdnsfor</font></td>"
}
else
{
Add-Content $report " <td bgcolor=$TableSuccessColor align=center>$dupdnsfor</td>"
}
Add-Content $report " </tr>"
Add-Content $report " <tr>"
Add-Content $report " <th title='Active Directory relies heavily in Domain Name System. Duplicate zones can cause numerous issues and should be investigated.'>Duplicated DNS Zones (Domain)</th>"
if ($dupdnsdom -ge 1)
{
Add-Content $report " <td bgcolor=$TableErrorColor align=center><font color=$TableFontOnError>$dupdnsdom</font></td>"
}
else
{
Add-Content $report " <td bgcolor=$TableSuccessColor align=center>$dupdnsdom</td>"
}
Add-Content $report " </tr>"