forked from adrecon/ADRecon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADRecon.ps1
13179 lines (11799 loc) · 579 KB
/
ADRecon.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
<#
.SYNOPSIS
ADRecon is a tool which gathers information about the Active Directory and generates a report which can provide a holistic picture of the current state of the target AD environment.
.DESCRIPTION
ADRecon is a tool which extracts and combines various artefacts (as highlighted below) out of an AD environment. The information can be presented in a specially formatted Microsoft Excel report that includes summary views with metrics to facilitate analysis and provide a holistic picture of the current state of the target AD environment.
The tool is useful to various classes of security professionals like auditors, DFIR, students, administrators, etc. It can also be an invaluable post-exploitation tool for a penetration tester.
It can be run from any workstation that is connected to the environment, even hosts that are not domain members. Furthermore, the tool can be executed in the context of a non-privileged (i.e. standard domain user) account.
Fine Grained Password Policy, LAPS and BitLocker may require Privileged user accounts.
The tool will use Microsoft Remote Server Administration Tools (RSAT) if available, otherwise it will communicate with the Domain Controller using LDAP.
The following information is gathered by the tool:
* Forest;
* Domain;
* Trusts;
* Sites;
* Subnets;
* Schema History;
* Default and Fine Grained Password Policy (if implemented);
* Domain Controllers, SMB versions, whether SMB Signing is supported and FSMO roles;
* Users and their attributes;
* Service Principal Names (SPNs);
* Groups, memberships and changes;
* Organizational Units (OUs);
* GroupPolicy objects and gPLink details;
* DNS Zones and Records;
* Printers;
* Computers and their attributes;
* PasswordAttributes (Experimental);
* LAPS passwords (if implemented);
* BitLocker Recovery Keys (if implemented);
* ACLs (DACLs and SACLs) for the Domain, OUs, Root Containers, GPO, Users, Computers and Groups objects (not included in the default collection method);
* GPOReport (requires RSAT);
* Kerberoast (not included in the default collection method); and
* Domain accounts used for service accounts (requires privileged account and not included in the default collection method).
Author : Prashant Mahajan
.NOTES
The following commands can be used to turn off ExecutionPolicy: (Requires Admin Privs)
PS > $ExecPolicy = Get-ExecutionPolicy
PS > Set-ExecutionPolicy bypass
PS > .\ADRecon.ps1
PS > Set-ExecutionPolicy $ExecPolicy
OR
Start the PowerShell as follows:
powershell.exe -ep bypass
OR
Already have a PowerShell open ?
PS > $Env:PSExecutionPolicyPreference = 'Bypass'
OR
powershell.exe -nologo -executionpolicy bypass -noprofile -file ADRecon.ps1
.PARAMETER Method
Which method to use; ADWS (default), LDAP
.PARAMETER DomainController
Domain Controller IP Address or Domain FQDN.
.PARAMETER Credential
Domain Credentials.
.PARAMETER GenExcel
Path for ADRecon output folder containing the CSV files to generate the ADRecon-Report.xlsx. Use it to generate the ADRecon-Report.xlsx when Microsoft Excel is not installed on the host used to run ADRecon.
.PARAMETER OutputDir
Path for ADRecon output folder to save the files and the ADRecon-Report.xlsx. (The folder specified will be created if it doesn't exist)
.PARAMETER Collect
Which modules to run; Comma separated; e.g Forest,Domain (Default all except Kerberoast, DomainAccountsusedforServiceLogon)
Valid values include: Forest, Domain, Trusts, Sites, Subnets, SchemaHistory, PasswordPolicy, FineGrainedPasswordPolicy, DomainControllers, Users, UserSPNs, PasswordAttributes, Groups, GroupChanges, GroupMembers, OUs, GPOs, gPLinks, DNSZones, DNSRecords, Printers, Computers, ComputerSPNs, LAPS, BitLocker, ACLs, GPOReport, Kerberoast, DomainAccountsusedforServiceLogon.
.PARAMETER OutputType
Output Type; Comma seperated; e.g STDOUT,CSV,XML,JSON,HTML,Excel (Default STDOUT with -Collect parameter, else CSV and Excel).
Valid values include: STDOUT, CSV, XML, JSON, HTML, Excel, All (excludes STDOUT).
.PARAMETER DormantTimeSpan
Timespan for Dormant accounts. (Default 90 days)
.PARAMETER PassMaxAge
Maximum machine account password age. (Default 30 days)
.PARAMETER PageSize
The PageSize to set for the LDAP searcher object.
.PARAMETER Threads
The number of threads to use during processing objects. (Default 10)
.PARAMETER OnlyEnabled
Only collect details for enabled objects. (Default $false)
.PARAMETER Log
Create ADRecon Log using Start-Transcript
.PARAMETER Logo
Which Logo to use in the excel file? (Default ADRecon)
Values include ADRecon, CyberCX, Payatu.
.EXAMPLE
.\ADRecon.ps1 -GenExcel C:\ADRecon-Report-<timestamp>
[*] ADRecon <version> by Prashant Mahajan (@prashant3535)
[*] Generating ADRecon-Report.xlsx
[+] Excelsheet Saved to: C:\ADRecon-Report-<timestamp>\<domain>-ADRecon-Report.xlsx
.EXAMPLE
.\ADRecon.ps1 -DomainController <IP or FQDN> -Credential <domain\username>
[*] ADRecon <version> by Prashant Mahajan (@prashant3535)
[*] Running on <domain>\<hostname> - Member Workstation as <user>
<snip>
Example output from Domain Member with Alternate Credentials.
.EXAMPLE
.\ADRecon.ps1 -DomainController <IP or FQDN> -Credential <domain\username> -Collect DomainControllers -OutputType Excel
[*] ADRecon <version> by Prashant Mahajan (@prashant3535)
[*] Running on WORKGROUP\<hostname> - Standalone Workstation as <user>
[*] Commencing - <timestamp>
[-] Domain Controllers
[*] Total Execution Time (mins): <minutes>
[*] Generating ADRecon-Report.xlsx
[+] Excelsheet Saved to: C:\ADRecon-Report-<timestamp>\<domain>-ADRecon-Report.xlsx
[*] Completed.
[*] Output Directory: C:\ADRecon-Report-<timestamp>
Example output from from a Non-Member using RSAT to only enumerate Domain Controllers.
.EXAMPLE
.\ADRecon.ps1 -Method ADWS -DomainController <IP or FQDN> -Credential <domain\username>
[*] ADRecon <version> by Prashant Mahajan (@prashant3535)
[*] Running on WORKGROUP\<hostname> - Standalone Workstation as <user>
[*] Commencing - <timestamp>
[-] Domain
[-] Forest
[-] Trusts
[-] Sites
[-] Subnets
[-] SchemaHistory - May take some time
[-] Default Password Policy
[-] Fine Grained Password Policy - May need a Privileged Account
[-] Domain Controllers
[-] Users and SPNs - May take some time
[-] PasswordAttributes - Experimental
[-] Groups and Membership Changes - May take some time
[-] Group Memberships - May take some time
[-] OrganizationalUnits (OUs)
[-] GPOs
[-] gPLinks - Scope of Management (SOM)
[-] DNS Zones and Records
[-] Printers
[-] Computers and SPNs - May take some time
[-] LAPS - Needs Privileged Account
WARNING: [*] LAPS is not implemented.
[-] BitLocker Recovery Keys - Needs Privileged Account
[-] GPOReport - May take some time
WARNING: [*] Run the tool using RUNAS.
WARNING: [*] runas /user:<Domain FQDN>\<Username> /netonly powershell.exe
[*] Total Execution Time (mins): <minutes>
[*] Output Directory: C:\ADRecon-Report-<timestamp>
[*] Generating ADRecon-Report.xlsx
[+] Excelsheet Saved to: C:\ADRecon-Report-<timestamp>\<domain>-ADRecon-Report.xlsx
Example output from a Non-Member using RSAT.
.EXAMPLE
.\ADRecon.ps1 -Method LDAP -DomainController <IP or FQDN> -Credential <domain\username>
[*] ADRecon <version> by Prashant Mahajan (@prashant3535)
[*] Running on WORKGROUP\<hostname> - Standalone Workstation as <user>
[*] LDAP bind Successful
[*] Commencing - <timestamp>
[-] Domain
[-] Forest
[-] Trusts
[-] Sites
[-] Subnets
[-] SchemaHistory - May take some time
[-] Default Password Policy
[-] Fine Grained Password Policy - May need a Privileged Account
[-] Domain Controllers
[-] Users and SPNs - May take some time
[-] PasswordAttributes - Experimental
[-] Groups and Membership Changes - May take some time
[-] Group Memberships - May take some time
[-] OrganizationalUnits (OUs)
[-] GPOs
[-] gPLinks - Scope of Management (SOM)
[-] DNS Zones and Records
[-] Printers
[-] Computers and SPNs - May take some time
[-] LAPS - Needs Privileged Account
WARNING: [*] LAPS is not implemented.
[-] BitLocker Recovery Keys - Needs Privileged Account
[-] GPOReport - May take some time
WARNING: [*] Currently, the module is only supported with ADWS.
[*] Total Execution Time (mins): <minutes>
[*] Output Directory: C:\ADRecon-Report-<timestamp>
[*] Generating ADRecon-Report.xlsx
[+] Excelsheet Saved to: C:\ADRecon-Report-<timestamp>\<domain>-ADRecon-Report.xlsx
Example output from a Non-Member using LDAP.
.LINK
https://github.com/adrecon/ADRecon
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $false, HelpMessage = "Which method to use; ADWS (default), LDAP")]
[ValidateSet('ADWS', 'LDAP')]
[string] $Method = 'ADWS',
[Parameter(Mandatory = $false, HelpMessage = "Domain Controller IP Address or Domain FQDN.")]
[string] $DomainController = '',
[Parameter(Mandatory = $false, HelpMessage = "Domain Credentials.")]
[Management.Automation.PSCredential] $Credential = [Management.Automation.PSCredential]::Empty,
[Parameter(Mandatory = $false, HelpMessage = "Path for ADRecon output folder containing the CSV files to generate the ADRecon-Report.xlsx. Use it to generate the ADRecon-Report.xlsx when Microsoft Excel is not installed on the host used to run ADRecon.")]
[string] $GenExcel,
[Parameter(Mandatory = $false, HelpMessage = "Path for ADRecon output folder to save the CSV/XML/JSON/HTML files and the ADRecon-Report.xlsx. (The folder specified will be created if it doesn't exist)")]
[string] $OutputDir,
[Parameter(Mandatory = $false, HelpMessage = "Which modules to run; Comma separated; e.g Forest,Domain (Default all except ACLs, Kerberoast and DomainAccountsusedforServiceLogon) Valid values include: Forest, Domain, Trusts, Sites, Subnets, SchemaHistory, PasswordPolicy, FineGrainedPasswordPolicy, DomainControllers, Users, UserSPNs, PasswordAttributes, Groups, GroupChanges, GroupMembers, OUs, GPOs, gPLinks, DNSZones, DNSRecords, Printers, Computers, ComputerSPNs, LAPS, BitLocker, ACLs, GPOReport, Kerberoast, DomainAccountsusedforServiceLogon")]
[ValidateSet('Forest', 'Domain', 'Trusts', 'Sites', 'Subnets', 'SchemaHistory', 'PasswordPolicy', 'FineGrainedPasswordPolicy', 'DomainControllers', 'Users', 'UserSPNs', 'PasswordAttributes', 'Groups', 'GroupChanges', 'GroupMembers', 'OUs', 'GPOs', 'gPLinks', 'DNSZones', 'DNSRecords', 'Printers', 'Computers', 'ComputerSPNs', 'LAPS', 'BitLocker', 'ACLs', 'GPOReport', 'Kerberoast', 'DomainAccountsusedforServiceLogon', 'Default')]
[array] $Collect = 'Default',
[Parameter(Mandatory = $false, HelpMessage = "Output type; Comma seperated; e.g STDOUT,CSV,XML,JSON,HTML,Excel (Default STDOUT with -Collect parameter, else CSV and Excel)")]
[ValidateSet('STDOUT', 'CSV', 'XML', 'JSON', 'EXCEL', 'HTML', 'All', 'Default')]
[array] $OutputType = 'Default',
[Parameter(Mandatory = $false, HelpMessage = "Timespan for Dormant accounts. Default 90 days")]
[ValidateRange(1,1000)]
[int] $DormantTimeSpan = 90,
[Parameter(Mandatory = $false, HelpMessage = "Maximum machine account password age. Default 30 days")]
[ValidateRange(1,1000)]
[int] $PassMaxAge = 30,
[Parameter(Mandatory = $false, HelpMessage = "The PageSize to set for the LDAP searcher object. Default 200")]
[ValidateRange(1,10000)]
[int] $PageSize = 200,
[Parameter(Mandatory = $false, HelpMessage = "The number of threads to use during processing of objects. Default 10")]
[ValidateRange(1,100)]
[int] $Threads = 10,
[Parameter(Mandatory = $false, HelpMessage = "Only collect details for enabled objects. Default `$false")]
[bool] $OnlyEnabled = $false,
[Parameter(Mandatory = $false, HelpMessage = "Create ADRecon Log using Start-Transcript.")]
[switch] $Log,
[Parameter(Mandatory = $false, HelpMessage = "Which Logo to use in the excel file? Default ADRecon")]
[ValidateSet('ADRecon', 'CyberCX', 'Payatu')]
[string] $Logo = "ADRecon"
)
$ADWSSource = @"
// Thanks Dennis Albuquerque for the C# multithreading code
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Threading;
using System.DirectoryServices;
//using System.Security.Principal;
using System.Security.AccessControl;
using System.Management.Automation;
using System.Diagnostics;
//using System.IO;
//using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Runtime.InteropServices;
namespace ADRecon
{
public static class ADWSClass
{
private static DateTime Date1;
private static int PassMaxAge;
private static int DormantTimeSpan;
private static Dictionary<string, string> AdGroupDictionary = new Dictionary<string, string>();
private static string DomainSID;
private static Dictionary<string, string> AdGPODictionary = new Dictionary<string, string>();
private static Hashtable GUIDs = new Hashtable();
private static Dictionary<string, string> AdSIDDictionary = new Dictionary<string, string>();
private static readonly HashSet<string> Groups = new HashSet<string> ( new string[] {"268435456", "268435457", "536870912", "536870913"} );
private static readonly HashSet<string> Users = new HashSet<string> ( new string[] { "805306368" } );
private static readonly HashSet<string> Computers = new HashSet<string> ( new string[] { "805306369" }) ;
private static readonly HashSet<string> TrustAccounts = new HashSet<string> ( new string[] { "805306370" } );
[Flags]
//Values taken from https://support.microsoft.com/en-au/kb/305144
public enum UACFlags
{
SCRIPT = 1, // 0x1
ACCOUNTDISABLE = 2, // 0x2
HOMEDIR_REQUIRED = 8, // 0x8
LOCKOUT = 16, // 0x10
PASSWD_NOTREQD = 32, // 0x20
PASSWD_CANT_CHANGE = 64, // 0x40
ENCRYPTED_TEXT_PASSWORD_ALLOWED = 128, // 0x80
TEMP_DUPLICATE_ACCOUNT = 256, // 0x100
NORMAL_ACCOUNT = 512, // 0x200
INTERDOMAIN_TRUST_ACCOUNT = 2048, // 0x800
WORKSTATION_TRUST_ACCOUNT = 4096, // 0x1000
SERVER_TRUST_ACCOUNT = 8192, // 0x2000
DONT_EXPIRE_PASSWD = 65536, // 0x10000
MNS_LOGON_ACCOUNT = 131072, // 0x20000
SMARTCARD_REQUIRED = 262144, // 0x40000
TRUSTED_FOR_DELEGATION = 524288, // 0x80000
NOT_DELEGATED = 1048576, // 0x100000
USE_DES_KEY_ONLY = 2097152, // 0x200000
DONT_REQUIRE_PREAUTH = 4194304, // 0x400000
PASSWORD_EXPIRED = 8388608, // 0x800000
TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION = 16777216, // 0x1000000
PARTIAL_SECRETS_ACCOUNT = 67108864 // 0x04000000
}
[Flags]
//Values taken from https://blogs.msdn.microsoft.com/openspecification/2011/05/30/windows-configurations-for-kerberos-supported-encryption-type/
public enum KerbEncFlags
{
ZERO = 0,
DES_CBC_CRC = 1, // 0x1
DES_CBC_MD5 = 2, // 0x2
RC4_HMAC = 4, // 0x4
AES128_CTS_HMAC_SHA1_96 = 8, // 0x18
AES256_CTS_HMAC_SHA1_96 = 16 // 0x10
}
private static readonly Dictionary<string, string> Replacements = new Dictionary<string, string>()
{
//{System.Environment.NewLine, ""},
//{",", ";"},
{"\"", "'"}
};
public static string CleanString(Object StringtoClean)
{
// Remove extra spaces and new lines
string CleanedString = string.Join(" ", ((Convert.ToString(StringtoClean)).Split((string[]) null, StringSplitOptions.RemoveEmptyEntries)));
foreach (string Replacement in Replacements.Keys)
{
CleanedString = CleanedString.Replace(Replacement, Replacements[Replacement]);
}
return CleanedString;
}
public static int ObjectCount(Object[] ADRObject)
{
return ADRObject.Length;
}
public static Object[] DomainControllerParser(Object[] AdDomainControllers, int numOfThreads)
{
Object[] ADRObj = runProcessor(AdDomainControllers, numOfThreads, "DomainControllers");
return ADRObj;
}
public static Object[] SchemaParser(Object[] AdSchemas, int numOfThreads)
{
Object[] ADRObj = runProcessor(AdSchemas, numOfThreads, "SchemaHistory");
return ADRObj;
}
public static Object[] UserParser(Object[] AdUsers, DateTime Date1, int DormantTimeSpan, int PassMaxAge, int numOfThreads)
{
ADWSClass.Date1 = Date1;
ADWSClass.DormantTimeSpan = DormantTimeSpan;
ADWSClass.PassMaxAge = PassMaxAge;
Object[] ADRObj = runProcessor(AdUsers, numOfThreads, "Users");
return ADRObj;
}
public static Object[] UserSPNParser(Object[] AdUsers, int numOfThreads)
{
Object[] ADRObj = runProcessor(AdUsers, numOfThreads, "UserSPNs");
return ADRObj;
}
public static Object[] GroupParser(Object[] AdGroups, int numOfThreads)
{
Object[] ADRObj = runProcessor(AdGroups, numOfThreads, "Groups");
return ADRObj;
}
public static Object[] GroupChangeParser(Object[] AdGroups, DateTime Date1, int numOfThreads)
{
ADWSClass.Date1 = Date1;
Object[] ADRObj = runProcessor(AdGroups, numOfThreads, "GroupChanges");
return ADRObj;
}
public static Object[] GroupMemberParser(Object[] AdGroups, Object[] AdGroupMembers, string DomainSID, int numOfThreads)
{
ADWSClass.AdGroupDictionary = new Dictionary<string, string>();
runProcessor(AdGroups, numOfThreads, "GroupsDictionary");
ADWSClass.DomainSID = DomainSID;
Object[] ADRObj = runProcessor(AdGroupMembers, numOfThreads, "GroupMembers");
return ADRObj;
}
public static Object[] OUParser(Object[] AdOUs, int numOfThreads)
{
Object[] ADRObj = runProcessor(AdOUs, numOfThreads, "OUs");
return ADRObj;
}
public static Object[] GPOParser(Object[] AdGPOs, int numOfThreads)
{
Object[] ADRObj = runProcessor(AdGPOs, numOfThreads, "GPOs");
return ADRObj;
}
public static Object[] SOMParser(Object[] AdGPOs, Object[] AdSOMs, int numOfThreads)
{
ADWSClass.AdGPODictionary = new Dictionary<string, string>();
runProcessor(AdGPOs, numOfThreads, "GPOsDictionary");
Object[] ADRObj = runProcessor(AdSOMs, numOfThreads, "SOMs");
return ADRObj;
}
public static Object[] PrinterParser(Object[] ADPrinters, int numOfThreads)
{
Object[] ADRObj = runProcessor(ADPrinters, numOfThreads, "Printers");
return ADRObj;
}
public static Object[] ComputerParser(Object[] AdComputers, DateTime Date1, int DormantTimeSpan, int PassMaxAge, int numOfThreads)
{
ADWSClass.Date1 = Date1;
ADWSClass.DormantTimeSpan = DormantTimeSpan;
ADWSClass.PassMaxAge = PassMaxAge;
Object[] ADRObj = runProcessor(AdComputers, numOfThreads, "Computers");
return ADRObj;
}
public static Object[] ComputerSPNParser(Object[] AdComputers, int numOfThreads)
{
Object[] ADRObj = runProcessor(AdComputers, numOfThreads, "ComputerSPNs");
return ADRObj;
}
public static Object[] LAPSParser(Object[] AdComputers, int numOfThreads)
{
Object[] ADRObj = runProcessor(AdComputers, numOfThreads, "LAPS");
return ADRObj;
}
public static Object[] DACLParser(Object[] ADObjects, Object PSGUIDs, int numOfThreads)
{
ADWSClass.AdSIDDictionary = new Dictionary<string, string>();
runProcessor(ADObjects, numOfThreads, "SIDDictionary");
ADWSClass.GUIDs = (Hashtable) PSGUIDs;
Object[] ADRObj = runProcessor(ADObjects, numOfThreads, "DACLs");
return ADRObj;
}
public static Object[] SACLParser(Object[] ADObjects, Object PSGUIDs, int numOfThreads)
{
ADWSClass.GUIDs = (Hashtable) PSGUIDs;
Object[] ADRObj = runProcessor(ADObjects, numOfThreads, "SACLs");
return ADRObj;
}
static Object[] runProcessor(Object[] arrayToProcess, int numOfThreads, string processorType)
{
int totalRecords = arrayToProcess.Length;
IRecordProcessor recordProcessor = recordProcessorFactory(processorType);
IResultsHandler resultsHandler = new SimpleResultsHandler ();
int numberOfRecordsPerThread = totalRecords / numOfThreads;
int remainders = totalRecords % numOfThreads;
Thread[] threads = new Thread[numOfThreads];
for (int i = 0; i < numOfThreads; i++)
{
int numberOfRecordsToProcess = numberOfRecordsPerThread;
if (i == (numOfThreads - 1))
{
//last thread, do the remaining records
numberOfRecordsToProcess += remainders;
}
//split the full array into chunks to be given to different threads
Object[] sliceToProcess = new Object[numberOfRecordsToProcess];
Array.Copy(arrayToProcess, i * numberOfRecordsPerThread, sliceToProcess, 0, numberOfRecordsToProcess);
ProcessorThread processorThread = new ProcessorThread(i, recordProcessor, resultsHandler, sliceToProcess);
threads[i] = new Thread(processorThread.processThreadRecords);
threads[i].Start();
}
foreach (Thread t in threads)
{
t.Join();
}
return resultsHandler.finalise();
}
static IRecordProcessor recordProcessorFactory(string name)
{
switch (name)
{
case "DomainControllers":
return new DomainControllerRecordProcessor();
case "SchemaHistory":
return new SchemaRecordProcessor();
case "Users":
return new UserRecordProcessor();
case "UserSPNs":
return new UserSPNRecordProcessor();
case "Groups":
return new GroupRecordProcessor();
case "GroupChanges":
return new GroupChangeRecordProcessor();
case "GroupsDictionary":
return new GroupRecordDictionaryProcessor();
case "GroupMembers":
return new GroupMemberRecordProcessor();
case "OUs":
return new OURecordProcessor();
case "GPOs":
return new GPORecordProcessor();
case "GPOsDictionary":
return new GPORecordDictionaryProcessor();
case "SOMs":
return new SOMRecordProcessor();
case "Printers":
return new PrinterRecordProcessor();
case "Computers":
return new ComputerRecordProcessor();
case "ComputerSPNs":
return new ComputerSPNRecordProcessor();
case "LAPS":
return new LAPSRecordProcessor();
case "SIDDictionary":
return new SIDRecordDictionaryProcessor();
case "DACLs":
return new DACLRecordProcessor();
case "SACLs":
return new SACLRecordProcessor();
}
throw new ArgumentException("Invalid processor type " + name);
}
class ProcessorThread
{
readonly int id;
readonly IRecordProcessor recordProcessor;
readonly IResultsHandler resultsHandler;
readonly Object[] objectsToBeProcessed;
public ProcessorThread(int id, IRecordProcessor recordProcessor, IResultsHandler resultsHandler, Object[] objectsToBeProcessed)
{
this.recordProcessor = recordProcessor;
this.id = id;
this.resultsHandler = resultsHandler;
this.objectsToBeProcessed = objectsToBeProcessed;
}
public void processThreadRecords()
{
for (int i = 0; i < objectsToBeProcessed.Length; i++)
{
Object[] result = recordProcessor.processRecord(objectsToBeProcessed[i]);
resultsHandler.processResults(result); //this is a thread safe operation
}
}
}
//The interface and implmentation class used to process a record (this implemmentation just returns a log type string)
interface IRecordProcessor
{
PSObject[] processRecord(Object record);
}
class DomainControllerRecordProcessor : IRecordProcessor
{
public PSObject[] processRecord(Object record)
{
try
{
PSObject AdDC = (PSObject) record;
bool Infra = false;
bool Naming = false;
bool Schema = false;
bool RID = false;
bool PDC = false;
PSObject DCSMBObj = new PSObject();
string OperatingSystem = CleanString((AdDC.Members["OperatingSystem"].Value != null ? AdDC.Members["OperatingSystem"].Value : "-") + " " + AdDC.Members["OperatingSystemHotfix"].Value + " " + AdDC.Members["OperatingSystemServicePack"].Value + " " + AdDC.Members["OperatingSystemVersion"].Value);
foreach (var OperationMasterRole in (Microsoft.ActiveDirectory.Management.ADPropertyValueCollection) AdDC.Members["OperationMasterRoles"].Value)
{
switch (OperationMasterRole.ToString())
{
case "InfrastructureMaster":
Infra = true;
break;
case "DomainNamingMaster":
Naming = true;
break;
case "SchemaMaster":
Schema = true;
break;
case "RIDMaster":
RID = true;
break;
case "PDCEmulator":
PDC = true;
break;
}
}
PSObject DCObj = new PSObject();
DCObj.Members.Add(new PSNoteProperty("Domain", AdDC.Members["Domain"].Value));
DCObj.Members.Add(new PSNoteProperty("Site", AdDC.Members["Site"].Value));
DCObj.Members.Add(new PSNoteProperty("Name", AdDC.Members["Name"].Value));
DCObj.Members.Add(new PSNoteProperty("IPv4Address", AdDC.Members["IPv4Address"].Value));
DCObj.Members.Add(new PSNoteProperty("Operating System", OperatingSystem));
DCObj.Members.Add(new PSNoteProperty("Hostname", AdDC.Members["HostName"].Value));
DCObj.Members.Add(new PSNoteProperty("Infra", Infra));
DCObj.Members.Add(new PSNoteProperty("Naming", Naming));
DCObj.Members.Add(new PSNoteProperty("Schema", Schema));
DCObj.Members.Add(new PSNoteProperty("RID", RID));
DCObj.Members.Add(new PSNoteProperty("PDC", PDC));
if (AdDC.Members["IPv4Address"].Value != null)
{
DCSMBObj = GetPSObject(AdDC.Members["IPv4Address"].Value);
}
else
{
DCSMBObj = new PSObject();
DCSMBObj.Members.Add(new PSNoteProperty("SMB Port Open", false));
}
foreach (PSPropertyInfo psPropertyInfo in DCSMBObj.Properties)
{
if (Convert.ToString(psPropertyInfo.Name) == "SMB Port Open" && (bool) psPropertyInfo.Value == false)
{
DCObj.Members.Add(new PSNoteProperty(psPropertyInfo.Name, psPropertyInfo.Value));
DCObj.Members.Add(new PSNoteProperty("SMB1(NT LM 0.12)", null));
DCObj.Members.Add(new PSNoteProperty("SMB2(0x0202)", null));
DCObj.Members.Add(new PSNoteProperty("SMB2(0x0210)", null));
DCObj.Members.Add(new PSNoteProperty("SMB3(0x0300)", null));
DCObj.Members.Add(new PSNoteProperty("SMB3(0x0302)", null));
DCObj.Members.Add(new PSNoteProperty("SMB3(0x0311)", null));
DCObj.Members.Add(new PSNoteProperty("SMB Signing", null));
break;
}
else
{
DCObj.Members.Add(new PSNoteProperty(psPropertyInfo.Name, psPropertyInfo.Value));
}
}
return new PSObject[] { DCObj };
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
return new PSObject[] { };
}
}
}
class SchemaRecordProcessor : IRecordProcessor
{
public PSObject[] processRecord(Object record)
{
try
{
PSObject AdSchema = (PSObject) record;
PSObject SchemaObj = new PSObject();
SchemaObj.Members.Add(new PSNoteProperty("ObjectClass", AdSchema.Members["ObjectClass"].Value));
SchemaObj.Members.Add(new PSNoteProperty("Name", AdSchema.Members["Name"].Value));
SchemaObj.Members.Add(new PSNoteProperty("whenCreated", AdSchema.Members["whenCreated"].Value));
SchemaObj.Members.Add(new PSNoteProperty("whenChanged", AdSchema.Members["whenChanged"].Value));
SchemaObj.Members.Add(new PSNoteProperty("DistinguishedName", AdSchema.Members["DistinguishedName"].Value));
return new PSObject[] { SchemaObj };
}
catch (Exception e)
{
Console.WriteLine("Exception caught: {0}", e);
return new PSObject[] { };
}
}
}
class UserRecordProcessor : IRecordProcessor
{
public PSObject[] processRecord(Object record)
{
try
{
PSObject AdUser = (PSObject) record;
bool? Enabled = null;
bool MustChangePasswordatLogon = false;
bool PasswordNotChangedafterMaxAge = false;
bool NeverLoggedIn = false;
int? DaysSinceLastLogon = null;
int? DaysSinceLastPasswordChange = null;
int? AccountExpirationNumofDays = null;
bool Dormant = false;
string SIDHistory = "";
bool? KerberosRC4 = null;
bool? KerberosAES128 = null;
bool? KerberosAES256 = null;
string DelegationType = null;
string DelegationProtocol = null;
string DelegationServices = null;
DateTime? LastLogonDate = null;
DateTime? PasswordLastSet = null;
DateTime? AccountExpires = null;
bool? AccountNotDelegated = null;
bool? HasSPN = null;
try
{
// The Enabled field can be blank which raises an exception. This may occur when the user is not allowed to query the UserAccountControl attribute.
Enabled = (bool) AdUser.Members["Enabled"].Value;
}
catch //(Exception e)
{
//Console.WriteLine("Exception caught: {0}", e);
}
if (AdUser.Members["lastLogonTimeStamp"].Value != null)
{
//LastLogonDate = DateTime.FromFileTime((long)(AdUser.Members["lastLogonTimeStamp"].Value));
// LastLogonDate is lastLogonTimeStamp converted to local time
LastLogonDate = Convert.ToDateTime(AdUser.Members["LastLogonDate"].Value);
DaysSinceLastLogon = Math.Abs((Date1 - (DateTime)LastLogonDate).Days);
if (DaysSinceLastLogon > DormantTimeSpan)
{
Dormant = true;
}
}
else
{
NeverLoggedIn = true;
}
if (Convert.ToString(AdUser.Members["pwdLastSet"].Value) == "0")
{
if ((bool) AdUser.Members["PasswordNeverExpires"].Value == false)
{
MustChangePasswordatLogon = true;
}
}
if (AdUser.Members["PasswordLastSet"].Value != null)
{
//PasswordLastSet = DateTime.FromFileTime((long)(AdUser.Members["pwdLastSet"].Value));
// PasswordLastSet is pwdLastSet converted to local time
PasswordLastSet = Convert.ToDateTime(AdUser.Members["PasswordLastSet"].Value);
DaysSinceLastPasswordChange = Math.Abs((Date1 - (DateTime)PasswordLastSet).Days);
if (DaysSinceLastPasswordChange > PassMaxAge)
{
PasswordNotChangedafterMaxAge = true;
}
}
//https://msdn.microsoft.com/en-us/library/ms675098(v=vs.85).aspx
//if ((Int64) AdUser.Members["accountExpires"].Value != (Int64) 9223372036854775807)
//{
//if ((Int64) AdUser.Members["accountExpires"].Value != (Int64) 0)
if (AdUser.Members["AccountExpirationDate"].Value != null)
{
try
{
//AccountExpires = DateTime.FromFileTime((long)(AdUser.Members["accountExpires"].Value));
// AccountExpirationDate is accountExpires converted to local time
AccountExpires = Convert.ToDateTime(AdUser.Members["AccountExpirationDate"].Value);
AccountExpirationNumofDays = ((int)((DateTime)AccountExpires - Date1).Days);
}
catch //(Exception e)
{
//Console.WriteLine("Exception caught: {0}", e);
}
}
//}
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection history = (Microsoft.ActiveDirectory.Management.ADPropertyValueCollection) AdUser.Members["SIDHistory"].Value;
string sids = "";
foreach (var value in history)
{
sids = sids + "," + Convert.ToString(value);
}
SIDHistory = sids.TrimStart(',');
if (AdUser.Members["msDS-SupportedEncryptionTypes"].Value != null)
{
var userKerbEncFlags = (KerbEncFlags) AdUser.Members["msDS-SupportedEncryptionTypes"].Value;
if (userKerbEncFlags != KerbEncFlags.ZERO)
{
KerberosRC4 = (userKerbEncFlags & KerbEncFlags.RC4_HMAC) == KerbEncFlags.RC4_HMAC;
KerberosAES128 = (userKerbEncFlags & KerbEncFlags.AES128_CTS_HMAC_SHA1_96) == KerbEncFlags.AES128_CTS_HMAC_SHA1_96;
KerberosAES256 = (userKerbEncFlags & KerbEncFlags.AES256_CTS_HMAC_SHA1_96) == KerbEncFlags.AES256_CTS_HMAC_SHA1_96;
}
}
if (AdUser.Members["UserAccountControl"].Value != null)
{
AccountNotDelegated = !((bool) AdUser.Members["AccountNotDelegated"].Value);
if ((bool) AdUser.Members["TrustedForDelegation"].Value)
{
DelegationType = "Unconstrained";
DelegationServices = "Any";
}
if (AdUser.Members["msDS-AllowedToDelegateTo"] != null)
{
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection delegateto = (Microsoft.ActiveDirectory.Management.ADPropertyValueCollection) AdUser.Members["msDS-AllowedToDelegateTo"].Value;
if (delegateto.Value != null)
{
DelegationType = "Constrained";
foreach (var value in delegateto)
{
DelegationServices = DelegationServices + "," + Convert.ToString(value);
}
DelegationServices = DelegationServices.TrimStart(',');
}
}
if ((bool) AdUser.Members["TrustedToAuthForDelegation"].Value == true)
{
DelegationProtocol = "Any";
}
else if (DelegationType != null)
{
DelegationProtocol = "Kerberos";
}
}
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection SPNs = (Microsoft.ActiveDirectory.Management.ADPropertyValueCollection)AdUser.Members["servicePrincipalName"].Value;
if (SPNs.Value == null)
{
HasSPN = false;
}
else
{
HasSPN = true;
}
PSObject UserObj = new PSObject();
UserObj.Members.Add(new PSNoteProperty("UserName", CleanString(AdUser.Members["SamAccountName"].Value)));
UserObj.Members.Add(new PSNoteProperty("Name", CleanString(AdUser.Members["Name"].Value)));
UserObj.Members.Add(new PSNoteProperty("Enabled", Enabled));
UserObj.Members.Add(new PSNoteProperty("Must Change Password at Logon", MustChangePasswordatLogon));
UserObj.Members.Add(new PSNoteProperty("Cannot Change Password", AdUser.Members["CannotChangePassword"].Value));
UserObj.Members.Add(new PSNoteProperty("Password Never Expires", AdUser.Members["PasswordNeverExpires"].Value));
UserObj.Members.Add(new PSNoteProperty("Reversible Password Encryption", AdUser.Members["AllowReversiblePasswordEncryption"].Value));
UserObj.Members.Add(new PSNoteProperty("Smartcard Logon Required", AdUser.Members["SmartcardLogonRequired"].Value));
UserObj.Members.Add(new PSNoteProperty("Delegation Permitted", AccountNotDelegated));
UserObj.Members.Add(new PSNoteProperty("Kerberos DES Only", AdUser.Members["UseDESKeyOnly"].Value));
UserObj.Members.Add(new PSNoteProperty("Kerberos RC4", KerberosRC4));
UserObj.Members.Add(new PSNoteProperty("Kerberos AES-128bit", KerberosAES128));
UserObj.Members.Add(new PSNoteProperty("Kerberos AES-256bit", KerberosAES256));
UserObj.Members.Add(new PSNoteProperty("Does Not Require Pre Auth", AdUser.Members["DoesNotRequirePreAuth"].Value));
UserObj.Members.Add(new PSNoteProperty("Never Logged in", NeverLoggedIn));
UserObj.Members.Add(new PSNoteProperty("Logon Age (days)", DaysSinceLastLogon));
UserObj.Members.Add(new PSNoteProperty("Password Age (days)", DaysSinceLastPasswordChange));
UserObj.Members.Add(new PSNoteProperty("Dormant (> " + DormantTimeSpan + " days)", Dormant));
UserObj.Members.Add(new PSNoteProperty("Password Age (> " + PassMaxAge + " days)", PasswordNotChangedafterMaxAge));
UserObj.Members.Add(new PSNoteProperty("Account Locked Out", AdUser.Members["LockedOut"].Value));
UserObj.Members.Add(new PSNoteProperty("Password Expired", AdUser.Members["PasswordExpired"].Value));
UserObj.Members.Add(new PSNoteProperty("Password Not Required", AdUser.Members["PasswordNotRequired"].Value));
UserObj.Members.Add(new PSNoteProperty("Delegation Type", DelegationType));
UserObj.Members.Add(new PSNoteProperty("Delegation Protocol", DelegationProtocol));
UserObj.Members.Add(new PSNoteProperty("Delegation Services", DelegationServices));
UserObj.Members.Add(new PSNoteProperty("Logon Workstations", AdUser.Members["LogonWorkstations"].Value));
UserObj.Members.Add(new PSNoteProperty("AdminCount", AdUser.Members["AdminCount"].Value));
UserObj.Members.Add(new PSNoteProperty("Primary GroupID", AdUser.Members["primaryGroupID"].Value));
UserObj.Members.Add(new PSNoteProperty("SID", AdUser.Members["SID"].Value));
UserObj.Members.Add(new PSNoteProperty("SIDHistory", SIDHistory));
UserObj.Members.Add(new PSNoteProperty("HasSPN", HasSPN));
UserObj.Members.Add(new PSNoteProperty("Description", CleanString(AdUser.Members["Description"].Value)));
UserObj.Members.Add(new PSNoteProperty("Title", CleanString(AdUser.Members["Title"].Value)));
UserObj.Members.Add(new PSNoteProperty("Department", CleanString(AdUser.Members["Department"].Value)));
UserObj.Members.Add(new PSNoteProperty("Company", CleanString(AdUser.Members["Company"].Value)));
UserObj.Members.Add(new PSNoteProperty("Manager", CleanString(AdUser.Members["Manager"].Value)));
UserObj.Members.Add(new PSNoteProperty("Info", CleanString(AdUser.Members["Info"].Value)));
UserObj.Members.Add(new PSNoteProperty("Last Logon Date", LastLogonDate));
UserObj.Members.Add(new PSNoteProperty("Password LastSet", PasswordLastSet));
UserObj.Members.Add(new PSNoteProperty("Account Expiration Date", AccountExpires));
UserObj.Members.Add(new PSNoteProperty("Account Expiration (days)", AccountExpirationNumofDays));
UserObj.Members.Add(new PSNoteProperty("Mobile", CleanString(AdUser.Members["Mobile"].Value)));
UserObj.Members.Add(new PSNoteProperty("Email", CleanString(AdUser.Members["mail"].Value)));
UserObj.Members.Add(new PSNoteProperty("HomeDirectory", AdUser.Members["homeDirectory"].Value));
UserObj.Members.Add(new PSNoteProperty("ProfilePath", AdUser.Members["profilePath"].Value));
UserObj.Members.Add(new PSNoteProperty("ScriptPath", AdUser.Members["ScriptPath"].Value));
UserObj.Members.Add(new PSNoteProperty("UserAccountControl", AdUser.Members["UserAccountControl"].Value));
UserObj.Members.Add(new PSNoteProperty("First Name", CleanString(AdUser.Members["givenName"].Value)));
UserObj.Members.Add(new PSNoteProperty("Middle Name", CleanString(AdUser.Members["middleName"].Value)));
UserObj.Members.Add(new PSNoteProperty("Last Name", CleanString(AdUser.Members["sn"].Value)));
UserObj.Members.Add(new PSNoteProperty("Country", CleanString(AdUser.Members["c"].Value)));
UserObj.Members.Add(new PSNoteProperty("whenCreated", AdUser.Members["whenCreated"].Value));
UserObj.Members.Add(new PSNoteProperty("whenChanged", AdUser.Members["whenChanged"].Value));
UserObj.Members.Add(new PSNoteProperty("DistinguishedName", CleanString(AdUser.Members["DistinguishedName"].Value)));
UserObj.Members.Add(new PSNoteProperty("CanonicalName", CleanString(AdUser.Members["CanonicalName"].Value)));
return new PSObject[] { UserObj };
}
catch (Exception e)
{
Console.WriteLine("Exception caught: {0}", e);
return new PSObject[] { };
}
}
}
class UserSPNRecordProcessor : IRecordProcessor
{
public PSObject[] processRecord(Object record)
{
try
{
PSObject AdUser = (PSObject) record;
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection SPNs = (Microsoft.ActiveDirectory.Management.ADPropertyValueCollection)AdUser.Members["servicePrincipalName"].Value;
if (SPNs.Value == null)
{
return new PSObject[] { };
}
List<PSObject> SPNList = new List<PSObject>();
bool? Enabled = null;
string Memberof = null;
DateTime? PasswordLastSet = null;
// When the user is not allowed to query the UserAccountControl attribute.
if (AdUser.Members["userAccountControl"].Value != null)
{
var userFlags = (UACFlags) AdUser.Members["userAccountControl"].Value;
Enabled = !((userFlags & UACFlags.ACCOUNTDISABLE) == UACFlags.ACCOUNTDISABLE);
}
if (Convert.ToString(AdUser.Members["pwdLastSet"].Value) != "0")
{
PasswordLastSet = DateTime.FromFileTime((long)AdUser.Members["pwdLastSet"].Value);
}
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection MemberOfAttribute = (Microsoft.ActiveDirectory.Management.ADPropertyValueCollection)AdUser.Members["memberof"].Value;
if (MemberOfAttribute.Value != null)
{
foreach (string Member in MemberOfAttribute)
{
Memberof = Memberof + "," + ((Convert.ToString(Member)).Split(',')[0]).Split('=')[1];
}
Memberof = Memberof.TrimStart(',');
}
string Description = CleanString(AdUser.Members["Description"].Value);
string PrimaryGroupID = Convert.ToString(AdUser.Members["primaryGroupID"].Value);
foreach (string SPN in SPNs)
{
string[] SPNArray = SPN.Split('/');
PSObject UserSPNObj = new PSObject();
UserSPNObj.Members.Add(new PSNoteProperty("Username", CleanString(AdUser.Members["SamAccountName"].Value)));
UserSPNObj.Members.Add(new PSNoteProperty("Name", CleanString(AdUser.Members["Name"].Value)));
UserSPNObj.Members.Add(new PSNoteProperty("Enabled", Enabled));
UserSPNObj.Members.Add(new PSNoteProperty("Service", SPNArray[0]));
UserSPNObj.Members.Add(new PSNoteProperty("Host", SPNArray[1]));
UserSPNObj.Members.Add(new PSNoteProperty("Password Last Set", PasswordLastSet));
UserSPNObj.Members.Add(new PSNoteProperty("Description", Description));
UserSPNObj.Members.Add(new PSNoteProperty("Primary GroupID", PrimaryGroupID));
UserSPNObj.Members.Add(new PSNoteProperty("Memberof", Memberof));
SPNList.Add( UserSPNObj );
}
return SPNList.ToArray();
}
catch (Exception e)
{
Console.WriteLine("Exception caught: {0}", e);
return new PSObject[] { };
}
}
}
class GroupRecordProcessor : IRecordProcessor
{
public PSObject[] processRecord(Object record)
{
try
{
PSObject AdGroup = (PSObject) record;
string ManagedByValue = Convert.ToString(AdGroup.Members["managedBy"].Value);
string ManagedBy = "";
string SIDHistory = "";
if (AdGroup.Members["managedBy"].Value != null)
{