-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-ADReport.ps1
1548 lines (873 loc) · 51.2 KB
/
Get-ADReport.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
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
# Load PowerShell module for Active Directory
Import-Module ActiveDirectory
# Custom function to scan specified AD domain and collect data
function Get-DomainInfo($DomainName)
{
Write-Host ""
Write-Host -ForegroundColor white -BackgroundColor black "Collecting Active Directory data..."
# Start of data collection for specified domain by function
$DomainInfo = Get-ADDomain $DomainName
# Variables definition
$domainSID = $DomainInfo.DomainSID
$domainDN = $DomainInfo.DistinguishedName
$domain = $DomainInfo.DNSRoot
$NetBIOS = $DomainInfo.NetBIOSName
$dfl = $DomainInfo.DomainMode
# Domain FSMO roles
$FSMOPDC = $DomainInfo.PDCEmulator
$FSMORID = $DomainInfo.RIDMaster
$FSMOInfrastructure = $DomainInfo.InfrastructureMaster
$DClist = $DomainInfo.ReplicaDirectoryServers
$RODCList = $DomainInfo.ReadOnlyReplicaDirectoryServers
$cmp_location = $DomainInfo.ComputersContainer
$usr_location = $DomainInfo.UsersContainer
$FGPPNo = "feature not supported"
# Get Domain Controller with at least Windows Server 2008 R2 OS
$DCListFiltered = Get-ADDomainController -Server $domain -Filter { operatingSystem -like "Windows Server 2008 R2*" -or operatingSystem -like "Windows Server 2012*" -or operatingSystem -like "Windows Server Technical Preview" } | Select * -ExpandProperty Name
$DCListFiltered | %{ $DCListFilteredIndex = $DCListFilteredIndex+1 }
# End of 2008R2 DC list
# if only one Windows Server 2008R2 Domain Controller exists
if ( $DCListFilteredIndex -eq 1 )
{
# Get information about Default Domain Password Policy
$pwdGPO = Get-ADDefaultDomainPasswordPolicy -Server $DCListFiltered
# check DFL and get Fine-Grained Password Policies
if ( $dfl -like "Windows2008Domain" -or $dfl -like "Windows2008R2Domain" -or $dfl -like "Windows2012Domain" -or $dfl -like "Windows2012R2Domain" )
{
$FGPPNo = (Get-ADFineGrainedPasswordPolicy -Server $DCListFiltered -Filter * | Measure-Object).Count
}
# End of Fine-Grained Password Policies section
# Get information about built-in domain Administrator account
$builtinAdmin = Get-ADuser -Identity $domainSID-500 -Server $DCListFiltered -Properties Name, LastLogonDate, PasswordLastSet, PasswordNeverExpires, whenCreated, Enabled
# Get total number of Domain Administrator group members
$domainAdminsNo = (Get-ADGroup -Identity $domainSID-512 -Server $DCListFiltered | Get-ADGroupMember -Recursive | Measure-Object).Count
}
# End main IF section
# if there are more than one Windows Server 2008R2 Domain Controllers
else
{
# Get information about Default Domain Password Policy from the first DC on the list
$pwdGPO = Get-ADDefaultDomainPasswordPolicy -Server $DCListFiltered[0]
# check DFL and get Fine-Grained Password Policies
if ( $dfl -like "Windows2008Domain" -or $dfl -like "Windows2008R2Domain" -or $dfl -like "Windows2012Domain" -or $dfl -like "Windows2012R2Domain" )
{
$FGPPNo = (Get-ADFineGrainedPasswordPolicy -Server $DCListFiltered[0] -Filter * | Measure-Object).Count
}
# End of Fine-Grained Password Policies section
# Get information about built-in domain Administrator account
$builtinAdmin = Get-ADuser -Identity $domainSID-500 -Server $DCListFiltered[0] -Properties Name, LastLogonDate, PasswordLastSet, PasswordNeverExpires, whenCreated, Enabled
# Get total number of Domain Administrators group members
$domainAdminsNo = (Get-ADGroup -Identity $domainSID-512 -Server $DCListFiltered[0] | Get-ADGroupMember -Recursive | Measure-Object).Count
}
# End main ELSE section
$usr_objectsNo = 0
$usr_active_objectsNo = 0
$usr_inactive_objectsNo = 0
$usr_locked_objectsNo = 0
$usr_pwdnotreq_objectsNo = 0
$usr_pwdnotexp_objectsNo = 0
$grp_objectsNo = 0
$grp_objects_localNo = 0
$grp_objects_universalNo = 0
$grp_objects_globalNo = 0
$cmp_objectsNo = 0
$cmp_os_2000 = 0
$cmp_os_xp = 0
$cmp_os_7 = 0
$cmp_os_8 = 0
$cmp_os_81 = 0
$cmp_os_10 = 0
$cmp_os_11 = 0
$cmp_srvos_2000 = 0
$cmp_srvos_2003 = 0
$cmp_srvos_2008 = 0
$cmp_srvos_2008r2 = 0
$cmp_srvos_2012 = 0
$cmp_srvos_2012r2 = 0
$cmp_srvos_2016 = 0
$cmp_srvos_2019 = 0
# Get information about Active Directory objects
$ou_objectsNo = (Get-ADOrganizationalUnit -Server $domain -Filter * | Measure-Object).Count
$cmp_objects = Get-ADComputer -Server $domain -Filter * -Properties operatingSystem
$cmp_objectsNo = $cmp_objects.Count
$cmp_objects | %{ if ($_.operatingSystem -like "Windows 2000 Professional*") { $cmp_os_2000 = $cmp_os_2000 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows XP*") { $cmp_os_xp = $cmp_os_xp + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows 7*") { $cmp_os_7 = $cmp_os_7 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows 8 *") { $cmp_os_8 = $cmp_os_8 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows 8.1*") { $cmp_os_81 = $cmp_os_81 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows 10*") { $cmp_os_10 = $cmp_os_10 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows 11*") { $cmp_os_11 = $cmp_os_11 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows 2000 Server*") { $cmp_srvos_2000 = $cmp_srvos_2000 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows Server 2003*") { $cmp_srvos_2003 = $cmp_srvos_2003 + 1 } }
$cmp_objects | %{ if ( ($_.operatingSystem -like "Windows Server 2008*") -and ($_.operatingSystem -notlike "Windows Server 2008 R2*") ) { $cmp_srvos_2008 = $cmp_srvos_2008 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows Server 2008 R2*") { $cmp_srvos_2008r2 = $cmp_srvos_2008r2 + 1 } }
$cmp_objects | %{ if ( ($_.operatingSystem -like "Windows Server 2012 *") -and ($_.operatingSystem -notlike "Windows Server 2012 R2*") ) { $cmp_srvos_2012 = $cmp_srvos_2012 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows Server 2012 R2*") { $cmp_srvos_2012r2 = $cmp_srvos_2012r2 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows Server 2016*") { $cmp_srvos_2016 = $cmp_srvos_2016 + 1 } }
$cmp_objects | %{ if ($_.operatingSystem -like "Windows Server 2019*") { $cmp_srvos_2019 = $cmp_srvos_2019 + 1 } }
$grp_objects = Get-ADGroup -Server $domain -Filter * -Properties GroupScope
$grp_objectsNo = $grp_objects.Count
$grp_objects | %{ if ($_.GroupScope -eq "DomainLocal") { $grp_objects_localNo = $grp_objects_localNo + 1 } }
$grp_objects | %{ if ($_.GroupScope -eq "Universal") { $grp_objects_universalNo = $grp_objects_universalNo + 1 } }
$grp_objects | %{ if ($_.GroupScope -eq "Global") { $grp_objects_globalNo = $grp_objects_globalNo + 1 } }
$usr_objects = Get-ADUser -Server $domain -Filter * -Properties Enabled, LockedOut, PasswordNeverExpires, PasswordNotRequired
$usr_objectsNo = $usr_objects.Count
$usr_objects | %{ if ($_.Enabled -eq $True) { $usr_active_objectsNo = $usr_active_objectsNo + 1 } }
$usr_objects | %{ if ($_.Enabled -eq $False) { $usr_inactive_objectsNo = $usr_inactive_objectsNo + 1 } }
$usr_objects | %{ if ($_.LockedOut -eq $True) { $usr_locked_objectsNo = $usr_locked_objectsNo + 1 } }
$usr_objects | %{ if ($_.PasswordNotRequired -eq $True) { $usr_pwdnotreq_objectsNo = $usr_pwdnotreq_objectsNo + 1 } }
$usr_objects | %{ if ($_.PasswordNeverExpires -eq $True) { $usr_pwdnotexp_objectsNo = $usr_pwdnotexp_objectsNo + 1 } }
# Display gathered domain details on the screen
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor yellow -BackgroundColor black "Current domain details: " -NoNewline
Write-Host ""
Write-Host "DNS domain name: " -NoNewline
Write-Host -ForegroundColor green $domain
Write-Host ""
Write-Host "NetBIOS domain name: " -NoNewline
Write-Host -ForegroundColor green $NetBIOS
Write-Host ""
# Check and display DFL
Write-Host "Domain Functional Level: " -NoNewline
switch ($dfl)
{
Windows2000Domain { Write-Host -ForegroundColor green "Windows 2000 native" }
Windows2003Domain { Write-Host -ForegroundColor green "Windows Server 2003" }
Windows2008Domain { Write-Host -ForegroundColor green "Windows Server 2008" }
Windows2008R2Domain { Write-Host -ForegroundColor green "Windows Server 2008 R2" }
Windows2012Domain { Write-Host -ForegroundColor green "Windows Server 2012" }
Windows2012R2Domain { Write-Host -ForegroundColor green "Windows Server 2012 R2" }
Windows2016Domain { Write-Host -ForegroundColor green "Windows Server 2016" }
Windows2019Domain { Write-Host -ForegroundColor green "Windows Server 2019" }
default { Write-Host -ForegroundColor red "Unknown Domain Functional Level:"$dfl }
}
Write-Host ""
# End DFL section
# SYSVOL replication method
Write-Host "SYSVOL replication method: " -NoNewline
$FRSsysvol = "CN=Domain System Volume (SYSVOL share),CN=File Replication Service,CN=System,"+(Get-ADDomain $domain).DistinguishedName
$DFSRsysvol = "CN=Domain System Volume,CN=DFSR-GlobalSettings,CN=System,"+(Get-ADDomain $domain).DistinguishedName
$frs = Get-ADObject -Filter { distinguishedName -eq $FRSsysvol }
$dfsr = Get-ADObject -Filter { distinguishedName -eq $DFSRsysvol }
if ( $frs -ne $nul ) { Write-Host -ForegroundColor red "FRS" }
elseif ( $dfsr -ne $nul ) { Write-Host -ForegroundColor green "DFS-R" }
else { Write-Host -ForegroundColor Red "unknown" }
Write-Host ""
# End of SYSVOL replication section
# List of Domain Controllers
Write-Host "List of Domain Controllers: " -NoNewline
$DCList | Sort | %{ Write-Host -ForegroundColor green $_.TrimEnd($domain).toUpper() }
Write-Host ""
Write-Host "List of Read-Only Domain Controllers: " -NoNewline
if ( $RODCList.Count -ne 0 )
{
$RODCList | %{ Write-Host -ForegroundColor green $_.TrimEnd($domain).toUpper() }
}
else
{
Write-Host -ForegroundColor green "(none)"
}
Write-Host ""
# End of Domain Controllers list section
# Global Catalogs in a domain
Write-Host "Global Catalog servers in the domain: " -NoNewline
$ForestGC | Sort | %{ if ( $_ -match $DomainName -and ((( $_ -replace $DomainName ) -split "\.").Count -eq 2 ))
{
Write-Host -ForegroundColor green ($_.TrimEnd($domain).toUpper()) }
}
Write-Host ""
# End of Global Catalogs section
# Display information about domain objects
# Domain computer objects location
Write-Host "Default domain computer objects location: " -NoNewline
if ($cmp_location.Contains("CN=Computers"))
{
Write-Host -ForegroundColor green $cmp_location -NoNewLine
Write-Host -ForegroundColor yellow " (not redirected)"
}
else
{
Write-Host -ForegroundColor green $cmp_location -NoNewLine
Write-Host -ForegroundColor red " (redirected)"
}
Write-Host ""
# End of domain computer objects location
# Domain user objects location
Write-Host "Default domain user objects location: " -NoNewline
if ($usr_location.Contains("CN=Users"))
{
Write-Host -ForegroundColor green $usr_location -NoNewLine
Write-Host -ForegroundColor yellow " (not redirected)"
}
else
{
Write-Host -ForegroundColor green $usr_location -NoNewLine
Write-Host -ForegroundColor red " (redirected)"
}
Write-Host ""
# End of domain user objects location
# Check if orphaned objects exist
Write-Host ""
Write-Host -ForegroundColor Yellow -BackgroundColor Black "Domain objects statistic: " -NoNewline
Write-Host ""
$orphaned = Get-ADObject -Filter * -SearchBase "cn=LostAndFound,$($domainDN)" -SearchScope OneLevel | Measure-Object
if ($orphaned.Count -ne 0)
{
Write-Host -ForegroundColor Red "$($orphaned.Count) orphaned objects have been found!"
}
else
{
Write-Host -ForegroundColor Green "No orphaned objects have been found"
}
# End of orphaned objects check
# Check if lingering objects or conflict replication objects exist
$lingConfRepl = Get-ADObject -LDAPFilter "(cn=*\0ACNF:*)" -SearchBase $domainDN -SearchScope SubTree | Measure-Object
if ($lingConfRepl.Count -ne 0)
{
Write-Host -ForegroundColor Red "$($lingConfRepl.Count) lingering or replication conflict objects have been found!"
}
else
{
Write-Host -ForegroundColor Green "No lingering or replication conflict objects have been found"
}
Write-Host ""
Write-Host ""
# End of lingering objects check
# Total number of Organizational Units
Write-Host "Total number of Organizational Unit objects : " -NoNewLine
Write-Host -ForegroundColor green $ou_objectsNo
Write-Host ""
Write-Host "Total number of computer objects : " -NoNewLine
Write-Host -ForegroundColor green $cmp_objectsNo
Write-Host ""
Write-Host " Client systems"
Write-host -ForegroundColor yellow " Windows 2000 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_os_2000
Write-host -ForegroundColor yellow " Windows XP : " -NoNewLine
Write-Host -ForegroundColor green $cmp_os_xp
Write-host -ForegroundColor yellow " Windows 7 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_os_7
Write-host -ForegroundColor yellow " Windows 8 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_os_8
Write-host -ForegroundColor yellow " Windows 8.1 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_os_81
Write-host -ForegroundColor yellow " Windows 10 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_os_10
Write-host -ForegroundColor yellow " Windows 11 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_os_11
Write-Host ""
Write-Host " Server systems"
Write-host -ForegroundColor yellow " Windows 2000 Server : " -NoNewLine
Write-Host -ForegroundColor green $cmp_srvos_2000
Write-host -ForegroundColor yellow " Windows Server 2003 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_srvos_2003
Write-host -ForegroundColor yellow " Windows Server 2008 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_srvos_2008
Write-host -ForegroundColor yellow " Windows Server 2008R2 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_srvos_2008r2
Write-host -ForegroundColor yellow " Windows Server 2012 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_srvos_2012
Write-host -ForegroundColor yellow " Windows Server 2012R2 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_srvos_2012r2
Write-host -ForegroundColor yellow " Windows Server 2016 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_srvos_2016
Write-host -ForegroundColor yellow " Windows Server 2019 : " -NoNewLine
Write-Host -ForegroundColor green $cmp_srvos_2019
Write-Host ""
# End of total OUs number
# Total number of domain users
Write-Host ""
Write-Host "Total number of user objects : " -NoNewLine
Write-Host -ForegroundColor green $usr_objectsNo
Write-host -ForegroundColor yellow " Active : " -NoNewLine
Write-Host -ForegroundColor green $usr_active_objectsNo
Write-host -ForegroundColor yellow " Inactive : " -NoNewLine
Write-Host -ForegroundColor green $usr_inactive_objectsNo
Write-host -ForegroundColor yellow " Locked out : " -NoNewLine
Write-Host -ForegroundColor green $usr_locked_objectsNo
Write-host -ForegroundColor yellow " Password not required : " -NoNewLine
Write-Host -ForegroundColor green $usr_pwdnotreq_objectsNo
Write-host -ForegroundColor yellow " Password never expires : " -NoNewLine
Write-Host -ForegroundColor green $usr_pwdnotexp_objectsNo
Write-Host ""
# End of total domain users number
# Total number of domain groups
Write-Host "Total number of group objects : " -NoNewLine
Write-Host -ForegroundColor green $grp_objectsNo
Write-Host -ForegroundColor yellow " Global : " -NoNewLine
Write-Host -ForegroundColor green $grp_objects_globalNo
Write-Host -ForegroundColor yellow " Universal : " -NoNewLine
Write-Host -ForegroundColor green $grp_objects_universalNo
Write-Host -ForegroundColor yellow " Domain Local : " -NoNewLine
Write-Host -ForegroundColor green $grp_objects_localNo
Write-Host ""
# End of total domain groups number
# Total number of domain administrators
Write-Host ""
Write-Host "Total number of Domain Administrators: " -NoNewline
if ( $domainAdminsNo -ge 1 -and $domainAdminsNo -le 5 )
{
Write-Host -ForegroundColor green $domainAdminsNo
}
else
{
Write-Host -ForegroundColor red $domainAdminsNo
}
Write-Host ""
Write-Host ""
# End of total domain administrators number
# Details about built-in domain Administrator account
Write-Host -ForegroundColor yellow -BackgroundColor black "Built-in Domain Administrator account details:"
Write-Host ""
Write-Host "Account name: " -NoNewline
Write-Host -ForegroundColor green $builtinAdmin.Name
Write-Host "Account status: " -NoNewline
if ( $builtinAdmin.Enabled )
{
Write-Host -ForegroundColor red "enabled"
}
else
{
Write-Host -ForegroundColor green "disabled"
}
Write-Host "Password never expires: " -NoNewline
if ( $builtinAdmin.PasswordNeverExpires )
{
Write-Host -ForegroundColor red "yes"
}
else
{
Write-Host -ForegroundColor green "no"
}
Write-Host ""
Write-Host "Promoted to domain account"
Write-Host -ForegroundColor green $builtinAdmin.whenCreated
Write-Host ""
Write-Host "Last password change"
Write-Host -ForegroundColor green $builtinAdmin.PasswordLastSet
Write-Host ""
Write-Host "Last logon date"
Write-Host -ForegroundColor green $builtinAdmin.LastLogonDate
Write-Host ""
Write-Host ""
# End of domain objects information section
# FSMO roles for domain
Write-Host -ForegroundColor yellow -BackgroundColor black "FSMO roles details:"
Write-Host ""
Write-Host "PDC Emulator master"
Write-Host -ForegroundColor green $FSMOPDC.toUpper()
Write-Host ""
Write-Host "RID master"
Write-Host -ForegroundColor green $FSMORID.toUpper()
Write-Host ""
Write-Host "Infrastructure master"
Write-Host -ForegroundColor green $FSMOInfrastructure.toUpper()
Write-Host ""
# End of domain FSMO section
# Check default domain policy existance
$gpoDefaultDomain = Get-ADObject -Server $domain -LDAPFilter "(&(objectClass=groupPolicyContainer)(cn={31B2F340-016D-11D2-945F-00C04FB984F9}))"
$gpoDefaultDomainController = Get-ADObject -Server $domain -LDAPFilter "(&(objectClass=groupPolicyContainer)(cn={6AC1786C-016F-11D2-945F-00C04fB984F9}))"
Write-Host -ForegroundColor yellow -BackgroundColor black "Default Domain policies check:"
Write-Host ""
if ($gpoDefaultDomain -ne $nul)
{
Write-Host "Default Domain policy : " -NoNewLine
Write-Host -ForegroundColor Green "exists"
}
else
{
Write-Host -ForegroundColor Red "does not exist"
}
if ($gpoDefaultDomainController -ne $nul)
{
Write-Host "Default Domain Controllers policy : " -NoNewLine
Write-Host -ForegroundColor Green "exists"
}
else
{
Write-Host -ForegroundColor Red "does not exist"
}
Write-Host ""
# End of default domain policies check
# Default Domain Password Policy details
Write-Host -ForegroundColor yellow -BackgroundColor black "Default Domain Password Policy details:"
Write-Host ""
Write-Host "Minimum password age: " -NoNewLine
Write-Host -ForegroundColor green $pwdGPO.MinPasswordAge.days "day(s)"
Write-Host "Maximum password age: " -NoNewLine
Write-Host -ForegroundColor green $pwdGPO.MaxPasswordAge.days "day(s)"
Write-Host "Minimum password length: " -NoNewline
Write-Host -ForegroundColor green $pwdGpo.MinPasswordLength "character(s)"
Write-Host "Password history count: " -NoNewLine
Write-Host -ForegroundColor green $pwdGPO.PasswordHistoryCount "unique password(s)"
Write-Host "Password must meet complexity: " -NoNewLine
if ( $pwdGPO.ComplexityEnabled )
{
Write-Host -ForegroundColor green "yes"
}
else
{
Write-Host -ForegroundColor red "no"
}
Write-Host "Password uses reversible encryption: " -NoNewLine
if ( $pwdGPO.ReversibleEncryptionEnabled )
{
Write-Host -ForegroundColor red "yes"
}
else
{
Write-Host -ForegroundColor green "no"
}
Write-Host ""
Write-Host "Account lockout treshold: " -NoNewLine
if ($pwdGPO.LockoutThreshold -eq 0 )
{
Write-Host -ForegroundColor red "Account never locks out"
}
else
{
Write-Host -ForegroundColor green $pwdGPO.LockoutThreshold "invalid logon attempts"
Write-Host "Account lockout duration time: " -NoNewline
if ( $pwdGPO.LockoutDuration.days -eq 0 -and $pwdGPO.LockoutDuration.hours -eq 0 -and $pwdGPO.LockoutDuration.minutes -eq 0 )
{
Write-Host -ForegroundColor red "Password may be unlocked by an administrator only"
}
else
{
Write-Host -ForegroundColor yellow $pwdGPO.LockoutDuration.days "day(s)"$pwdGPO.LockoutDuration.hours "hour(s)"$pwdGPO.LockoutDuration.minutes "min(s)"
Write-Host "Account lockout counter resets after: " -NoNewline
Write-Host -ForegroundColor yellow $pwdGPO.LockoutObservationWindow.days "day(s)"$pwdGPO.LockoutObservationWindow.hours "hour(s)"$pwdGPO.LockoutObservationWindow.minutes "min(s)"
}
}
# End of Default Domain Password Policy details
# Display total number of Fine-Grained Password Policies
Write-Host ""
Write-Host "Fine-Grained Password Policies: " -NoNewline
Write-Host -ForegroundColor green $FGPPNo
Write-Host ""
}
# End of custom Get-DomainInfo function
# Main script section
Clear-Host
Write-Host -ForegroundColor white -BackgroundColor black "Collecting Active Directory data..."
# Checking if PowerShell script was executed with a parameter
if ( $args.Length -gt 0 )
{
# Collecting information about specified Forest configuration
$ForestInfo=Get-ADForest $args[0]
}
else
{
# Collecting information about current Forest configuration
$ForestInfo=Get-ADForest
}
# End of parameter check
# Forest variables definition
$forest=$ForestInfo.RootDomain
$allDomains=$ForestInfo.Domains
$ForestGC=$ForestInfo.GlobalCatalogs
$UPNsuffix=$ForestInfo.UPNSuffixes
$ffl=$ForestInfo.ForestMode
$FSMODomainNaming=$ForestInfo.DomainNamingMaster
$FSMOSchema=$ForestInfo.SchemaMaster
$forestDomainSID = Get-ADDomain (Get-ADForest).Name | Select domainSID
$ADRecBinSupport="feature not supported"
if ( $ffl -like "Windows2008R2Forest" -or $ffl -like "Windows2012Forest" -or $ffl -like "Windows2012R2Forest" )
{
$ADRecBin=(Get-ADOptionalFeature -Server $forest -Identity 766ddcd8-acd0-445e-f3b9-a7f9b6744f2a).EnabledScopes | Measure-Object
if ( $ADRecBin.Count -ne 0 )
{
$ADRecBinSupport="Enabled"
}
else
{
$ADRecBinSupport="Disabled"
}
}
# End of forest variables section
# Define Schema partition variables
$SchemaPartition = $ForestInfo.PartitionsContainer.Replace("CN=Partitions","CN=Schema")
$SchemaVersion = Get-ADObject -Server $forest -Identity $SchemaPartition -Properties * | Select objectVersion
# End of Schema partition variables definition
$forestDN = $ForestInfo.PartitionsContainer.Replace("CN=Partitions,CN=Configuration,","")
$configPartition = $ForestInfo.PartitionsContainer.Replace("CN=Partitions,","")
# Display collected data
Clear-Host
Write-Host -ForegroundColor white -BackgroundColor black "Active Directory report v0.2 by Krzysztof Pytko (iSiek)"
Write-Host ""
Write-Host ""
# Display information about Forest
Write-Host -ForegroundColor yellow -BackgroundColor black "Forest details:"
Write-Host ""
Write-Host "Forest name: " -NoNewline
Write-Host -ForegroundColor green $forest
Write-Host ""
# Determine and display schema version
Write-Host "Active Directory schema version: " -NoNewline
switch ($SchemaVersion.objectVersion)
{
13 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows 2000 Server" }
30 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 2003" }
31 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 2003 R2" }
44 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 2008" }
47 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 2008 R2" }
51 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 8 Developers Preview" }
52 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 8 Beta" }
56 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 2012" }
69 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 2012 R2" }
72 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server Technical Preview" }
87 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 2016" }
88 { Write-Host -ForegroundColor green $SchemaVersion.objectVersion "- Windows Server 2019" }
default { Write-Host -ForegroundColor red "unknown - "$SchemaVersion.objectVersion }
}
Write-Host ""
# End of schema version section
# Determine and display Exchange version
Write-Host "Microsoft Exchange version: " -NoNewline
$ExchangeSystemObjects = Get-ADObject -Server $forest -LDAPFilter "(&(objectClass=container)(name=Microsoft Exchange System Objects))" -SearchBase $forestDN -Properties objectVersion
$ExchangeSchemaVersion = Get-ADObject -Server $forest -LDAPFilter "(&(objectClass=attributeSchema)(name=ms-Exch-Schema-Version-Pt))" -SearchBase $SchemaPartition -Properties rangeUpper
$ExchangeSchema = $ExchangeSystemObjects.objectVersion + $ExchangeSchemaVersion.rangeUpper
if ($ExchangeSchemaVersion -ne $nul)
{
switch ($ExchangeSchema)
{
13806 { Write-Host -ForegroundColor green "Exchange Server 2003" }
21265 { Write-Host -ForegroundColor green "Exchange Server 2007" }
22337 { Write-Host -ForegroundColor green "Exchange Server 2007 Service Pack 1" }
25843 { Write-Host -ForegroundColor green "Exchange Server 2007 Service Pack 2" }
25846 { Write-Host -ForegroundColor green "Exchange Server 2007 Service Pack 3" }
27261 { Write-Host -ForegroundColor green "Exchange Server 2010" }
27766 { Write-Host -ForegroundColor green "Exchange Server 2010 Service Pack 1" }
27772 { Write-Host -ForegroundColor green "Exchange Server 2010 Service Pack 2" }
27774 { Write-Host -ForegroundColor green "Exchange Server 2010 Service Pack 3" }
28373 { Write-Host -ForegroundColor green "Exchange Server 2013" }
28490 { Write-Host -ForegroundColor green "Exchange Server 2013 Cumulative Update 1" }
28517 { Write-Host -ForegroundColor green "Exchange Server 2013 Cumulative Update 2" }
28519 { Write-Host -ForegroundColor green "Exchange Server 2013 Cumulative Update 3" }
28528 { Write-Host -ForegroundColor green "Exchange Server 2013 Cumulative Update 4 - Service Pack 1" }
28536 { Write-Host -ForegroundColor green "Exchange Server 2013 Cumulative Update 5" }
28539 { Write-Host -ForegroundColor green "Exchange Server 2013 Cumulative Update 6" }
default { Write-Host -ForegroundColor red "unknown - "$ExchangeSchemaVersion.rangeUpper }
}
$ExchOrganization = (Get-ADObject -Server $forest -Identity "cn=Microsoft Exchange,cn=Services,$configPartition" -Properties templateRoots).templateRoots
$ExchOrgName = (Get-ADObject -Server $forest -Identity $($ExchOrganization -Replace "cn=Addressing," , "") -Properties name).name
Write-Host ""
Write-Host "Microsoft Exchange Organization name: " -NoNewline
Write-Host -ForegroundColor Green $ExchOrgName
} #end if
else
{
Write-Host -ForegroundColor green "(not present)"
}
Write-Host ""
# End of Exchange version
# Determine and display Lync version
Write-Host "Microsoft Lync server version: " -NoNewline
$LyncSchemaVersion = Get-ADObject -Server $forest -LDAPFilter "(&(objectClass=attributeSchema)(name=ms-RTC-SIP-SchemaVersion))" -SearchBase $SchemaPartition -Properties rangeUpper
if ($LyncSchemaVersion -ne $nul)
{
switch ($LyncSchemaVersion.rangeUpper)
{
1006 { Write-Host -ForegroundColor green "Live Communications Server 2005" }
1007 { Write-Host -ForegroundColor green "Office Communications Server 2007 Release 1" }
1008 { Write-Host -ForegroundColor green "Office Communications Server 2007 Release 2" }
1100 { Write-Host -ForegroundColor green "Lync Server 2010" }
1150 { Write-Host -ForegroundColor green "Lync Server 2013" }
default { Write-Host -ForegroundColor red "unknown - "$LyncSchemaVersion.rangeUpper }
}
}# end if
else
{
Write-Host -ForegroundColor green "(not present)"
}