-
Notifications
You must be signed in to change notification settings - Fork 6
/
ADDS_Tool.cmd
4655 lines (4426 loc) · 247 KB
/
ADDS_Tool.cmd
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
:::: Active Directory Domain Services Tool [ADDS] :::::::::::::::::::::::::::::
::#############################################################################
:: #DESCRIPTION#
::
:: SCRIPT STYLE: Interactive
:: Program is a wrapper for ADDS (Active Directory Domain Services)
:: Active Directory search's
::#############################################################################
:::: Developer ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Author: David Geeraerts
:: Location: Olympia, Washington USA
:: E-Mail: dgeeraerts.evergreen@gmail.com
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: GitHub :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: https://github.com/DavidGeeraerts/ADDS_Tool
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: License ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Copyleft License(s)
:: GNU GPL v3 (General Public License)
:: https://www.gnu.org/licenses/gpl-3.0.en.html
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Versioning Schema ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: VERSIONING INFORMATION ::
:: Semantic Versioning used ::
:: http://semver.org/ ::
:: Major.Minor.Revision ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Stopwatch start ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@SET $START_LOAD_TIME=%TIME%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Command shell ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@Echo Off
@SETLOCAL enableextensions
SET $PROGRAM_NAME=Active_Directory_Domain_Services_Tool
SET $Version=0.19.2
SET $BUILD=2023-05-05 0730
Title %$PROGRAM_NAME%
Prompt ADT$G
color 8F
mode con:cols=80 lines=56
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::###########################################################################::
:: Declare Global variables [Defaults]
::###########################################################################::
::: Configuration File ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET $CONFIG_FILE=ADDS_Tool.config
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Configuration - Basic ::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Declare Global variables
:: All User variables are set within here.
:: Defaults
:: uses user profile location for logs
SET "$LOGPATH=%APPDATA%\ADDS"
SET "$LOGPATH_ARCHIVE=%APPDATA%\ADDS"
SET $SESSION_LOG=ADDS_Tool_Active_Session.log
SET $SEARCH_SESSION_LOG=ADDS_Tool_Session_Search.log
SET $LAST_SEARCH_LOG=ADDS_Tool_Last_Search.log
SET $ARCHIVE_LOG=ADDS_Tool_Session_Archive.log
SET $ARCHIVE_SEARCH_LOG=ADDS_Tool_Search_Archive.log
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Configuration - Advanced :::::::::::::::::::::::::::::::::::::::::::::::::
:: Advanced Settings
:: Suppress_Verbose Output on searches
:: 0=Off {no}; 1=On {yes}
SET $SUPPRESS_VERBOSE=0
:: Sort --the search results
:: {0 [No] , 1 [Yes]}
SET $SORTED=1
:: Keep PID Session logs
:: {Yes, No}
SET $KPLOG=No
:: Nuke logs
:: {Yes, No}
SET $NUKE=No
:: Keep Session Settings
:: {Yes, No}
SET $SAVE_SETTINGS=Yes
:: Load Settings --from file
:: {0 [Off/No] , 1 [On/Yes]}
SET $LOAD_SETTINGS=Yes
:: DEBUG
:: {0 [Off/No] , 1 [On/Yes]}
SET $DEGUB_MODE=0
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::#############################################################################
:: !!!! Everything below here is 'hard-coded' [DO NOT MODIFY] !!!!
::#############################################################################
echo Loading...
:::: Directory ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CD
:: Launched from directory
SET "$PROGRAM_PATH=%~dp0"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Default Program Variables ::::::::::::::::::::::::::::::::::::::::::::::::
:: Program Variables
:: Defaults
SET $COUNTER_SEARCH=0
SET $sLimit=0
:: Domain User status
:: 0 - Local User , 1 - Domain User
SET $DU=1
SET $DC=%USERDOMAIN%
SET $SESSION_USER=%USERNAME%
SET $DOMAIN_USER=NA
SET $cUSERNAME=
SET $ADGROUP.N=NA
SET $SEARCH_TYPE=NA
SET $SEARCH_KEY=NA
SET $LAST_SEARCH_COUNT=NA
SET $DOMAIN=%USERDNSDOMAIN%
SET $DSITE=Default
IF NOT DEFINED $DOMAIN SET $DOMAIN=NA
REM Doesn't like On Off words
IF %$SORTED% EQU 1 (SET $SORTED_N=Yes) ELSE (SET $SORTED_N=No)
IF %$SUPPRESS_VERBOSE% EQU 0 (SET $SUPPRESS_VERBOSE_N=No) ELSE (SET $SUPPRESS_VERBOSE_N=Yes)
SET $SEARCH_SETTINGS_CHECK=0
SET $SEARCH_ATTRIBUTE=name
:: Defaults
SET $AD_BASE=domainroot
SET $AD_SCOPE=subtree
SET "$AD_SERVER_SEARCH=-s %$DC%"
:: Dependency Checks
:: assumes ready to go
SET $PREREQUISITE_STATUS=1
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::###########################################################################::
:: CONFIGURATION FILE OVERRIDE
::###########################################################################::
IF NOT EXIST "%~dp0\%$CONFIG_FILE%" Goto skipCF
:: FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"<$VARIABLE>" "%~dp0\%$CONFIG_FILE%"') DO SET "<$VARIABLE>=%%V"
:: ADDS_TOOL_CONFIG_SCHEMA_VERSION
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$CONFIG_SCHEMA_VERSION" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_SCHEMA_VERSION=%%V"
:: Logging
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$LOGPATH" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_LOGPATH=%%V"
IF DEFINED $CONFIG_LOGPATH SET "$LOGPATH=%$CONFIG_LOGPATH%"
FOR /F %%R IN ('ECHO %$LOGPATH%') DO SET $LOGPATH=%%R
:: Archive Logs
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$LOGPATH_ARCHIVE" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_LOGPATH_ARCHIVE=%%V"
IF DEFINED $CONFIG_LOGPATH_ARCHIVE SET "$LOGPATH_ARCHIVE=%$CONFIG_LOGPATH%"
FOR /F %%R IN ('ECHO %$LOGPATH_ARCHIVE%') DO SET $LOGPATH_ARCHIVE=%%R
:: Session log
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$SESSION_LOG" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_SESSION_LOG=%%V"
IF DEFINED $CONFIG_SESSION_LOG SET "$SESSION_LOG=%$CONFIG_SESSION_LOG%"
:: Session Search log
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$SEARCH_SESSION_LOG" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_SEARCH_SESSION_LOG=%%V"
IF DEFINED $CONFIG_SEARCH_SESSION_LOG SET "$SEARCH_SESSION_LOG=%$CONFIG_SEARCH_SESSION_LOG%"
:: Last search log
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$LAST_SEARCH_LOG" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_LAST_SEARCH_LOG=%%V"
IF DEFINED $CONFIG_LAST_SEARCH_LOG SET "$LAST_SEARCH_LOG=%$CONFIG_LAST_SEARCH_LOG%"
:: Archive Session log
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$ARCHIVE_LOG" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_ARCHIVE_LOG=%%V"
IF DEFINED $CONFIG_ARCHIVE_LOG SET "$ARCHIVE_LOG=%$CONFIG_ARCHIVE_LOG%"
:: Archive Search log
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$ARCHIVE_SEARCH_LOG" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_ARCHIVE_SEARCH_LOG=%%V"
IF DEFINED $CONFIG_ARCHIVE_SEARCH_LOG SET "$ARCHIVE_SEARCH_LOG=%$CONFIG_ARCHIVE_SEARCH_LOG%"
:: Search Defaults
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$sLimit" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_sLimit=%%V"
IF DEFINED $CONFIG_sLimit SET "$sLimit=%$CONFIG_sLimit%"
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$AD_BASE" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_AD_BASE=%%V"
IF DEFINED $CONFIG_AD_BASE SET "$AD_BASE=%$CONFIG_AD_BASE%"
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$AD_SCOPE" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_AD_SCOPE=%%V"
IF DEFINED $CONFIG_AD_SCOPE SET "$AD_SCOPE=%$CONFIG_AD_SCOPE%"
:: Credentials
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$DOMAIN_USER" "%~dp0\%$CONFIG_FILE%"') DO SET "$DOMAIN_USER=%%V"
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$DOMAIN_USER_PASSWORD" "%~dp0\%$CONFIG_FILE%"') DO SET "$DOMAIN_USER_PASSWORD=%%V"
REM Friendly name to variable name
IF DEFINED $DOMAIN_USER_PASSWORD SET $cUSERPASSWORD=%$DOMAIN_USER_PASSWORD%
:: Advanced Settings
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$DEGUB_MODE" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_DEGUB_MODE=%%V"
IF DEFINED $CONFIG_DEGUB_MODE SET "$DEGUB_MODE=%$CONFIG_DEGUB_MODE%"
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$SUPPRESS_VERBOSE" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_SUPPRESS_VERBOSE=%%V"
IF DEFINED $CONFIG_SUPPRESS_VERBOSE SET "$SUPPRESS_VERBOSE=%$CONFIG_SUPPRESS_VERBOSE%"
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$SORTED" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_SORTED=%%V"
IF DEFINED $CONFIG_SORTED SET "$SORTED=%$CONFIG_SORTED%"
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$KPLOG" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_KPLOG=%%V"
IF DEFINED $CONFIG_KPLOG SET "$KPLOG=%$CONFIG_KPLOG%"
FOR /F "tokens=2 delims=^=" %%V IN ('FINDSTR /BC:"$NUKE" "%~dp0\%$CONFIG_FILE%"') DO SET "$CONFIG_NUKE=%%V"
IF DEFINED $CONFIG_NUKE SET "$NUKE=%$CONFIG_NUKE%"
REM variable name to Friendly name
IF %$SORTED% EQU 1 (SET $SORTED_N=Yes) ELSE (SET $SORTED_N=No)
IF %$SUPPRESS_VERBOSE% EQU 0 (SET $SUPPRESS_VERBOSE_N=No) ELSE (SET $SUPPRESS_VERBOSE_N=Yes)
:skipCF
:::: Original Logging Path ::::::::::::::::::::::::::::::::::::::::::::::::::::
:BLPath
SET $BASE_LOGPATH=%$LOGPATH%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Temporary Cache ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:TCache
IF NOT EXIST "%$LOGPATH%\cache" MD "%$LOGPATH%\cache"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: PID ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:PID
:: Program information including PID
tasklist /FI "WINDOWTITLE eq %$PROGRAM_NAME%*" > "%$LogPath%\cache\var_TaskInfo_PID.txt"
for /F "skip=3 tokens=2 delims= " %%P IN ('tasklist /FI "WINDOWTITLE eq %$PROGRAM_NAME%*"') DO echo %%P> "%$LogPath%\cache\var_$PID.txt"
SET /P $PID= < "%$LogPath%\cache\var_$PID.txt"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: PID Session Logging ::::::::::::::::::::::::::::::::::::::::::::::::::::::
:PIDL
IF NOT EXIST "%$LOGPATH%\%$PID%" MD "%$LOGPATH%\%$PID%"
IF NOT EXIST "%$LOGPATH%\%$PID%\cache" MD "%$LOGPATH%\%$PID%\cache"
MOVE /Y "%$LogPath%\cache\var_$PID.txt" "%$LOGPATH%\%$PID%\cache"
RD /S /Q "%$LogPath%\cache" 2> nul
SET "$LOGPATH=%$LOGPATH%\%$PID%"
cd /D "%$BASE_LOGPATH%"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Logging Variables ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: mostly for debugging
echo %$LogPath%> "%$LOGPATH%\cache\var_$LOGPATH.txt"
echo %$BASE_LOGPATH%> "%$LOGPATH%\cache\var_$BASE_LOGPATH.txt"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: fISO8601 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:fISO8601
:: Function to ensure ISO 8601 Date format yyyy-mmm-dd
:: Easiest way to get ISO date
@powershell Get-Date -format "yyyy-MM-dd" > "%$LogPath%\cache\var_$ISO8601_Date.txt"
SET /P $ISO_DATE= < "%$LogPath%\cache\var_$ISO8601_Date.txt"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: UTC ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:UTC
:: Universal Time Coordinate
IF EXIST "%$LogPath%\cache\var_$UTC.txt" SET /P $UTC= < "%$LogPath%\cache\var_$UTC.txt"
IF NOT DEFINED $UTC FOR /F "tokens=1 delims=()" %%P IN ('wmic timezone get Description ^| findstr /C:"UTC" /I') DO ECHO %%P > "%$LogPath%\cache\var_$UTC.txt"
IF NOT DEFINED $UTC SET /P $UTC= < "%$LogPath%\cache\var_$UTC.txt"
IF EXIST "%$LogPath%\cache\var_$UTC_STANDARD_NAME.txt" SET /P $UTC_STANDARD_NAME= < "%$LogPath%\cache\var_$UTC_STANDARD_NAME.txt"
IF NOT DEFINED $UTC_STANDARD_NAME FOR /F "tokens=2 delims==" %%P IN ('wmic timezone get StandardName /value ^| findstr /C:"=" /I') DO ECHO %%P > "%$LogPath%\cache\var_$UTC_STANDARD_NAME.txt"
IF NOT DEFINED $UTC_STANDARD_NAME SET /P $UTC_STANDARD_NAME= < "%$LogPath%\cache\var_$UTC_STANDARD_NAME.txt"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Session Log Header :::::::::::::::::::::::::::::::::::::::::::::::::::::::
:wLog
:: Start session and write to log
Echo Start Session %DATE% %TIME% > "%$LogPath%\%$SESSION_LOG%"
echo UTC: %$UTC% %$UTC_STANDARD_NAME% >> "%$LogPath%\%$SESSION_LOG%"
Echo Program Name: %$PROGRAM_NAME% >> "%$LogPath%\%$SESSION_LOG%"
Echo Program Version: %$Version% >> "%$LogPath%\%$SESSION_LOG%"
Echo Program Build: %$BUILD% >> "%$LogPath%\%$SESSION_LOG%"
IF DEFINED $CONFIG_SCHEMA_VERSION echo Program config schema: %$CONFIG_SCHEMA_VERSION% >> "%$LogPath%\%$SESSION_LOG%"
echo Program Path: %$PROGRAM_PATH% >> "%$LogPath%\%$SESSION_LOG%"
Echo PC: %COMPUTERNAME% >> "%$LogPath%\%$SESSION_LOG%"
echo PC Domain: %USERDOMAIN% >> "%$LogPath%\%$SESSION_LOG%"
Echo Session User: %USERNAME% >> "%$LogPath%\%$SESSION_LOG%"
echo PID: %$PID% >> "%$LogPath%\%$SESSION_LOG%"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Computer Domain ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DUC
:: Check for Domain computer
:: If value is 1 domain, is 0 workgroup
SET $DOMAIN_PC=1
wmic computersystem get DomainRole /value | (FIND "0") && (SET $DOMAIN_PC=0)
echo %$DOMAIN_PC% > "%$LogPath%\cache\var_$DOMAIN_PC.txt"
if %$DOMAIN_PC% EQU 0 SET $DOMAIN=%COMPUTERNAME%
if %$DOMAIN_PC% EQU 1 SET $DOMAIN=%USERDNSDOMAIN%
:: Can be local or domain
IF %$DOMAIN_PC% EQU 0 SET $SESSION_USER_STATUS=local
IF %$DOMAIN_PC% EQU 0 GoTo skipDUC
:: Is domain user or local user?
whoami /UPN 2> nul || FOR /F "tokens=1-2 delims=\" %%P IN ('whoami') Do SET $DOMAIN=%%P && SET $DU=0
IF %$DU% EQU 0 SET $SESSION_USER_STATUS=local
IF %$DU% EQU 0 GoTo skipDUC
:: If domain user use UPN to set domain instead of USERDNSDOMAIN
FOR /F "tokens=2 delims=^@" %%P IN ('whoami /UPN') Do SET $DOMAIN=%%P
:: Default credentials for Active Directory is current logged on user.
:: can be changed in console program
SET $DC=%LOGONSERVER:~2%
SET $DOMAIN_USER=%USERNAME%
SET $SESSION_USER_STATUS=domain
:skipDUC
:: Friendly name
if %$DOMAIN_PC% EQU 0 SET $DOMAIN_PC_N=workgroup
if %$DOMAIN_PC% EQU 1 SET $DOMAIN_PC_N=domain
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Administrator Privilege Check ::::::::::::::::::::::::::::::::::::::::::::
:subA
openfiles.exe 1> "%$LOGPATH%\cache\var_$Admin_Status_M.txt" 2> "%$LOGPATH%\cache\var_$Admin_Status_E.txt"
SET $ADMIN_STATUS=0
FIND "ERROR:" "%$LOGPATH%\cache\var_$Admin_Status_E.txt" 2> nul > nul && (SET $ADMIN_STATUS=1)
IF %$ADMIN_STATUS% EQU 0 (SET "$ADMIN_STATUS_N=Yes") ELSE (SET "$ADMIN_STATUS_N=No")
echo %$ADMIN_STATUS_N%> "%$LOGPATH%\cache\var_$Admin_Status_N.txt"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Check RSAT-Remote Server Administration Tools ::::::::::::::::::::::::::::
:CheckRSAT
dsquery /? 1> nul 2> nul
SET $RSAT_STATUS=%ERRORLEVEL%
IF %$RSAT_STATUS% EQU 0 GoTo Start
:: Admin privileges required
IF %$ADMIN_STATUS% NEQ 0 GoTo err10
:: Remote Server Administrator Tools Message
:: Requires RSAT-Remote Server Administration Tools
mode con:cols=80 lines=40
cls
color 8B
SET PREREQUISITE_STATUS=0
Echo.
Echo It appears this computer [%COMPUTERNAME%] doesn't have:
Echo [RSAT] Remote Server Administration Tools installed!
Echo.
Echo Try installing "Remote Server Admin Tool --> AD DS and AD LDS Tools".
Echo Reference for doing this:
Echo https://support.microsoft.com/en-us/help/2693643/remote-server-administration-tools-rsat-for-windows-operating-systems
Echo.
echo Install RSAT?
set /p $INSTALL_DEPENDENCY=[Y]es or [N]o:
echo.
echo Selected: %$INSTALL_DEPENDENCY%
IF NOT DEFINED $INSTALL_DEPENDENCY GoTo skipRSAT
IF /I "%$INSTALL_DEPENDENCY%"=="N" GoTo skipRSAT
GoTo RSAT
Echo.
:skipRSAT
Timeout /t 10
GoTo end
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: RSAT Installer :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:RSAT
:: Requires RSAT-Remote Server Administration Tools
:: Active Directory Domain Services (AD DS) tools and Active Directory Lightweight Directory Services (AD LDS) tools
:: Requires administrative privileges!
:: Rsat.ActiveDirectory.DS-LDS.Tools
FOR /F "tokens=2 delims=:" %%P IN ('DISM /Online /Get-Capabilities ^| find /I "Rsat.ActiveDirectory.DS-LDS.Tools"') DO SET $RSAT_ADDS_FULL=%%P
:: remove leading space
FOR /F "tokens=1 delims= " %%P IN ("%$RSAT_ADDS_FULL%") DO SET $RSAT_ADDS_FULL=%%P
echo %$RSAT_ADDS_FULL%
:: RSAT Installation
ECHO Going to try to install RSAT (Remote Server Administration Tools)...
echo.
DISM /Online /add-capability /CapabilityName:%$RSAT_ADDS_FULL%
SET $DISM_ERR=%ERRORLEVEL%
echo $DISM_ERR:%DISM_STATUS%
::after install check
DISM /Online /Get-CapabilityInfo /CapabilityName:%$RSAT_ADDS_FULL% > "%$LOGPATH%\cache\var_DISM_ADDS.txt"
FIND /I "State : Installed" "%$LOGPATH%\cache\var_DISM_ADDS.txt"
type "%$LOGPATH%\cache\var_DISM_ADDS.txt" >> "%$LogPath%\%$SESSION_LOG%"
SET $RSAT_STATUS=%ERRORLEVEL%
IF %$RSAT_STATUS% NEQ 0 SET $PREREQUISITE_STATUS=%$RSAT_STATUS%
IF %$RSAT_STATUS% NEQ 0 GoTo err20
IF %$PREREQUISITE_STATUS% EQU 0 GoTo Start
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Stopwatch - Start ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Start
:: Capture program load time
@PowerShell.exe -c "$span=([TimeSpan]'%Time%' - [TimeSpan]'%$START_LOAD_TIME%'); '{0:00}:{1:00}:{2:00}.{3:00}' -f $span.Hours, $span.Minutes, $span.Seconds, $span.Milliseconds" > "%$LogPath%\cache\var_Load_Time.txt"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Parameters :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Param
:: Parameter #1 Search Type
SET $PARAMETER1=%~1
IF NOT DEFINED $PARAMETER1 GoTo skipParam
set $SEARCH_TYPE=%$PARAMETER1%
echo %$SEARCH_TYPE%> "%$LOGPATH%\cache\var_$SEARCH_TYPE.txt"
:: Parameter #2 Attribute
SET $PARAMETER2=%~2
IF NOT DEFINED $PARAMETER2 GoTo skipParam
set $SEARCH_ATTRIBUTE=%$PARAMETER2%
echo %$SEARCH_ATTRIBUTE%> "%$LOGPATH%\cache\var_$SEARCH_ATTRIBUTE.txt"
:: Parameter #3 Search Key
SET $PARAMETER3=%~3
IF NOT DEFINED $PARAMETER3 GoTo skipParam
set $SEARCH_KEY=%$PARAMETER3%
echo %$SEARCH_KEY%> "%$LOGPATH%\cache\var_$SEARCH_KEY.txt"
:: Automated Search
GoTo SAUTO
:skipParam
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Main Menu ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Menu
Color 0F
mode con:cols=58 lines=40
Cls
ECHO *********************************************************
ECHO %$PROGRAM_NAME%
echo Version: %$Version%
IF %$DEGUB_MODE% EQU 1 Echo Build: %$BUILD%
Echo PID: %$PID%
echo.
echo %DATE% %TIME%
ECHO.
Echo Location: Main Menu
ECHO *********************************************************
Echo.
ECHO Session Information:
Echo ------------------------
echo Session User: %USERNAME%
echo Session Admin Privilege: %$ADMIN_STATUS_N%
echo Session User Status: %$SESSION_USER_STATUS%
echo Session PC: %COMPUTERNAME%
echo Session PC Role: %$DOMAIN_PC_N%
echo.
echo Log Settings:
Echo ------------------------
Echo Log File Path: %$LogPath%
Echo Log File Name: %$SESSION_LOG%
Echo Keep PID Session Logs: %$kpLog%
Echo Nuke logs: %$NUKE%
Echo.
Echo Current Domain settings:
Echo ------------------------
Echo Domain Account: %$DOMAIN_USER%
Echo Domain: %$DOMAIN%
Echo Domain Controller: %$DC%
echo Domain Site: %$DSITE%
ECHO *********************************************************
Echo.
Echo Choose an action to perform from the list:
Echo.
Echo [1] Search
Echo [2] Settings
Echo [3] Logs
Echo [4] Exit
Echo.
Choice /c 1234
Echo.
::
If ERRORLevel 4 GoTo End
If ERRORLevel 3 GoTo Logs
If ERRORLevel 2 GoTo Uset
If ERRORLevel 1 GoTo Search
Echo.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Search Menu ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Search
Color 0A
mode con:cols=80 lines=52
:: Trap: Domain User check
echo %COMPUTERNAME% | (FIND /I "%$DOMAIN%") && (GoTo :subDomain)
IF %$DU% EQU 0 call :subDA
IF /I "%$DC%"=="%COMPUTERNAME%" call :subDC
call :SMB
Echo Choose search type from the list:
Echo.
Echo [1] Universal
Echo [2] User
Echo [3] Group
ECho [4] Computer
echo [5] Server ^(DC's^)
echo [6] OU
echo [7] Settings Menu
echo [8] Main Menu
Echo [9] Exit
Echo.
Choice /c 123456789
Echo.
If ERRORLevel 9 GoTo end
If ERRORLevel 8 GoTo Menu
If ERRORLevel 7 GoTo Uset
If ERRORLevel 6 GoTo sOU
If ERRORLevel 5 GoTo sServer
If ERRORLevel 4 GoTo sComputer
If ERRORLevel 3 GoTo sGroup
If ERRORLevel 2 GoTo sUser
If ERRORLevel 1 GoTo sUniversal
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ## START SUBROUTINES ## :::::::::::::::::::::::::::::::::::::::::::::::
:::: Search Menu Banner :::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SMB
Color 0A
mode con:cols=55 lines=40
Cls
ECHO ******************************************************
ECHO %$PROGRAM_NAME%
echo.
echo %DATE% %TIME%
ECHO.
Echo Location: Search Menu
Echo ******************************************************
Echo.
Echo Search Settings
Echo ------------------------
Echo AD Base: %$AD_BASE%
Echo AD Scope: %$AD_SCOPE%
Echo Query limit: %$sLimit%
echo Sorted: %$SORTED_N%
echo Suppress Verbose: %$Suppress_Verbose_N%
Echo Search count: %$COUNTER_SEARCH%
Echo ******************************************************
Echo.
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Search Menu Dashboard ::::::::::::::::::::::::::::::::::::::::::::::::::::
:SM
cls
ECHO ******************************************************
ECHO %$PROGRAM_NAME%
echo.
echo %DATE% %TIME%
ECHO.
Echo Location: %$LAST_SEARCH_TYPE% Search
Echo ******************************************************
echo.
Echo Domain Settings
Echo ------------------------
Echo Domain Running Account: %$DOMAIN_USER%
Echo Domain Controller: %$DC%
echo Domain Site: %$DSITE%
Echo Domain: %$domain%
echo.
Echo Search Settings
Echo ------------------------
Echo AD Base: %$AD_BASE%
Echo AD Scope: %$AD_SCOPE%
Echo Query limit: %$sLimit%
echo Sorted: %$SORTED_N%
echo Suppress Verbose: %$Suppress_Verbose_N%
echo.
echo Search HUD
Echo ------------------------
Echo Search count: %$COUNTER_SEARCH%
Echo Search Type: %$SEARCH_TYPE%
echo Search Attribute: %$SEARCH_ATTRIBUTE%
echo Search Key: %$SEARCH_KEY%
echo Search Results: %$LAST_SEARCH_COUNT%
Echo ******************************************************
echo.
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::: Sub-routin for Search Key :::::::::::::::::::::::::::::::::::::::::::::::
:subSK
:: # Future development
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Start Elapse Time ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:subSET
SET $START_TIME=%TIME%
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Total Lapse Time :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:subTLT
@PowerShell.exe -c "$span=([TimeSpan]'%Time%' - [TimeSpan]'%$START_TIME%'); '{0:00}:{1:00}:{2:00}.{3:00}' -f $span.Hours, $span.Minutes, $span.Seconds, $span.Milliseconds" > "%$LogPath%\cache\var_Total_Lapsed_Time.txt"
SET /P $TOTAL_LAPSE_TIME= < "%$LogPath%\cache\var_Total_Lapsed_Time.txt"
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Search Log Header ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:sHeader
IF EXIST "%$LogPath%\%$LAST_SEARCH_LOG%" DEL /Q "%$LogPath%\%$LAST_SEARCH_LOG%"
Echo Start search: %DATE% %Time% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo UTC: %$UTC% %$UTC_STANDARD_NAME% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
Echo Search Type: %$SEARCH_TYPE% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Search Attribute: %$SEARCH_ATTRIBUTE% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Search Key: %$SEARCH_KEY% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Search Sorted: %$SORTED_N% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Search AD Root: %$AD_BASE% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Search AD Scope: %$AD_SCOPE% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Domain Controller: %$DC% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
Echo Domain: %$DOMAIN% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Last Search Log Close - Notepad ::::::::::::::::::::::::::::::::::::::::::
:LSLCN
taskkill /F /FI "WINDOWTITLE eq %$LAST_SEARCH_LOG% - Notepad" 2>nul 1>nul
GoTo:EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ## END SUBROUTINES ## :: ::::::::::::::::::::::::::::::::::::::::::::::::
:::: Search Universal :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:sUniversal
:: Search Universal
:: Reset search variables for HUD
SET $SEARCH_TYPE=Universal
SET $SEARCH_ATTRIBUTE=
SET $SEARCH_KEY=
SET $LAST_SEARCH_COUNT=
:: Close previous Windows
:: Last Search Log Close - Notepad
call :LSLCN
call :SM
SET "$ATTRIBUTES_Universal=name cn displayName distinguishedName extensionAttribute<#> objectSid sAMAccountName"
@powershell Write-Host "Universal Attributes:" -ForegroundColor Gray
@powershell Write-Host "%$ATTRIBUTES_Universal%" -ForegroundColor Blue
:: User input
@powershell Write-Host "Choose attribute to search against:" -ForegroundColor Gray
@powershell Write-Host "default is name, leave blank for default" -ForegroundColor Magenta
SET /P $SEARCH_ATTRIBUTE=Attribute:
IF NOT DEFINED $SEARCH_ATTRIBUTE SET $SEARCH_ATTRIBUTE=name
call :SM
@powershell Write-Host "Attribute: %$SEARCH_ATTRIBUTE%" -ForegroundColor Blue
@powershell Write-Host "can use wildcard * : Key* *Key *key*" -ForegroundColor Gray
@powershell Write-Host "If left blank, will abort!" -ForegroundColor Red
SET /P $SEARCH_KEY=Choose a search key:
IF NOT DEFINED $SEARCH_KEY GoTo Search
call :SM
echo Selected {%$SEARCH_KEY%} as search key.
@powershell Write-Host "Searching..." -ForegroundColor DarkYellow
REM If Forestroot, then searches GC Global Catalog.
set "$AD_SERVER_SEARCH=-s %$DC%.%$DOMAIN%"
if %$AD_BASE%==forestroot SET "$AD_SERVER_SEARCH=-gc"
:: Start Elapse Time
call :subSET
call :sHeader
:: Credentials
:: Domain credentials default to blank
SET $DOMAIN_CREDENTIALS=
if not "%$SESSION_USER%"=="%$DOMAIN_USER%" SET "$DOMAIN_CREDENTIALS=-u %$DOMAIN_USER% -p %$cUSERPASSWORD%"
:: Debug
if %$DEGUB_MODE% EQU 1 CALL :fVarD
:: Check for sorted
if %$SORTED% EQU 1 GoTo jumpSUS
:: unsorted
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=*)(%$SEARCH_ATTRIBUTE%=%$SEARCH_KEY%))" -attr name displayName distinguishedName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% > "%$LogPath%\cache\var_Last_Search_N_DN.txt"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=*)(%$SEARCH_ATTRIBUTE%=%$SEARCH_KEY%))" -attr distinguishedName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% > "%$LogPath%\cache\var_Last_Search_DN.txt"
GoTo skipSUS
:jumpSUS
:: sorted
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=*)(%$SEARCH_ATTRIBUTE%=%$SEARCH_KEY%))" -attr name displayName distinguishedName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% | sort > "%$LogPath%\cache\var_Last_Search_N_DN.txt"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=*)(%$SEARCH_ATTRIBUTE%=%$SEARCH_KEY%))" -attr distinguishedName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% | sort > "%$LogPath%\cache\var_Last_Search_DN.txt"
:skipSUS
:: Check results
FOR /F "tokens=3 delims=:" %%K IN ('FIND /I /C "=" "%$LogPath%\cache\var_Last_Search_N_DN.txt"') DO echo %%K > "%$LogPath%\cache\var_Last_Search_Count.txt"
:: remove leading space
FOR /F "tokens=1 delims= " %%P IN (%$LogPath%\cache\var_Last_Search_Count.txt) DO echo %%P> "%$LogPath%\cache\var_Last_Search_Count.txt"
SET /P $LAST_SEARCH_COUNT= < "%$LogPath%\cache\var_Last_Search_Count.txt"
call :SM
IF %$LAST_SEARCH_COUNT% EQU 0 (
echo Number of search results: %$LAST_SEARCH_COUNT% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo End search: %DATE% %Time% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
TYPE "%$LogPath%\%$LAST_SEARCH_LOG%" >> "%$SEARCH_SESSION_LOG%"
@powershell Write-Host "Nothing found! Try again with broader wildcard" -ForegroundColor Red
GoTo skipSUC
)
:: Munge N_DN file
IF EXIST "%$LogPath%\cache\var_Last_Search_N_DN_munge.txt" DEL /Q /F "%$LogPath%\cache\var_Last_Search_N_DN_munge.txt"
FOR /F "skip=2 delims=" %%M IN ('FIND /I /V "distinguishedName" "%$LogPath%\cache\var_Last_Search_N_DN.txt"') DO echo %%M >> "%$LogPath%\cache\var_Last_Search_N_DN_munge.txt"
type "%$LogPath%\cache\var_Last_Search_N_DN_munge.txt" > "%$LogPath%\cache\var_Last_Search_N_DN.txt"
:: Munge DN file
IF EXIST "%$LogPath%\cache\var_Last_Search_DN_munge.txt" DEL /Q /F "%$LogPath%\cache\var_Last_Search_DN_munge.txt"
FOR /F "skip=2 delims=" %%M IN ('FIND /I /V "distinguishedName" "%$LogPath%\cache\var_Last_Search_DN.txt"') DO echo %%M >> "%$LogPath%\cache\var_Last_Search_DN_munge.txt"
type "%$LogPath%\cache\var_Last_Search_DN_munge.txt" > "%$LogPath%\cache\var_Last_Search_DN.txt"
:: Output search results
echo Number of search results: %$LAST_SEARCH_COUNT% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Number of search results: %$LAST_SEARCH_COUNT%
@powershell Write-Host "Processing..." -ForegroundColor DarkYellow
echo Name displayName distinguishedName >> "%$LogPath%\%$LAST_SEARCH_LOG%"
type "%$LogPath%\cache\var_Last_Search_N_DN.txt" >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
IF %$SUPPRESS_VERBOSE% EQU 1 GoTo jumpSUO
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Verbose Output: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
:: Detailed Output
REM powershell write output adds slight overhead.
REM e.g. 293 sarch result:
REM powershell Total Search Time: 00:07:52.610
REM echo Total Search Time: 00:05:34.370
FOR /F "tokens=* delims=" %%N IN (%$LogPath%\cache\var_Last_Search_DN.txt) DO (
(call :SM) & (
@powershell Write-Host "Processing verbose..." -ForegroundColor DarkYellow) & (
@powershell Write-Host '%%N' -ForegroundColor DarkGray) & (
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(distinguishedName=%%N)" -attr name %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%") & (
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(distinguishedName=%%N)" -attr description %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%") & (
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(distinguishedName=%%N)" -attr displayName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%") & (
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(distinguishedName=%%N)" -attr distinguishedName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%") & (
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%") & (
echo Details: >> "%$LogPath%\%$LAST_SEARCH_LOG%") & (
DSQUERY * -filter "(distinguishedName=%%N)" -attr * %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%") & (
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%") & (
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%")
)
:jumpSUO
call :subTLT
:: Search counter increment
Call :fSC
:: Refresh HUD
call :SM
echo Total Search Time: %$TOTAL_LAPSE_TIME%
echo Total Search Time: %$TOTAL_LAPSE_TIME% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo End search: %DATE% %Time% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
type "%$LogPath%\%$LAST_SEARCH_LOG%" >> "%$LogPath%\%$SEARCH_SESSION_LOG%"
:: Open log files
@explorer "%$LogPath%\%$LAST_SEARCH_LOG%"
:skipSUC
@powershell Write-Host "Search Again?" -ForegroundColor Gray
Choice /c YN /m "[Y]es or [N]o":
IF %ERRORLEVEL% EQU 2 GoTo Search
IF %ERRORLEVEL% EQU 1 GoTo sUniversal
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::: Search User Menu :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:sUser
:: Close previous Windows
call :LSLCN
SET $SEARCH_TYPE=User
SET $SEARCH_ATTRIBUTE=
SET $SEARCH_KEY=
call :SM
echo User search using:
echo.
echo [1] Name
echo [2] UPN
echo [3] First and Last name
echo [4] Display name
echo [5] Custom attribute search
echo [6] Global
echo [7] Search menu
echo.
Choice /c 1234567
echo.
If ERRORLevel 7 GoTo Search
If ERRORLevel 6 GoTo SUG
If ERRORLevel 5 GoTo SUCA
If ERRORLevel 4 GoTo SUDN
If ERRORLevel 3 GoTo SUFL
If ERRORLevel 2 GoTo SUU
If ERRORLevel 1 GoTo SUN
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::: Search User Name ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SUN
:: Reset Variables
SET $SEARCH_ATTRIBUTE=name
SET $SEARCH_KEY=
SET $LAST_SEARCH_COUNT=
:: Last Search Log Close - Notepad
call :LSLCN
call :SM
:: Console output
@powershell Write-Host "Attribute: Name" -ForegroundColor Blue
@powershell Write-Host "Can use "*" wildcard for search." -ForegroundColor Gray
@powershell Write-Host "If left blank, will abort." -ForegroundColor Magenta
SET /P $SEARCH_KEY=User name search key:
IF NOT DEFINED $SEARCH_KEY GoTo sUser
call :SM
echo Selected {%$SEARCH_KEY%} as name search key.
@powershell Write-Host "Searching..." -ForegroundColor DarkYellow
:: Start Elapse Time
call :subSET
:: Write log headers
call :sHeader
:: Credentials
:: Domain credentials default to blank
SET $DOMAIN_CREDENTIALS=
if not "%$SESSION_USER%"=="%$DOMAIN_USER%" SET "$DOMAIN_CREDENTIALS=-u %$DOMAIN_USER% -p %$cUSERPASSWORD%"
REM If Forestroot, then searches GC Global Catalog.
set "$AD_SERVER_SEARCH=-s %$DC%.%$DOMAIN%"
if %$AD_BASE%==forestroot SET "$AD_SERVER_SEARCH=-gc"
:: Debug
if %$DEGUB_MODE% EQU 1 CALL :fVarD
:: Check for sorted
if %$SORTED% EQU 1 GoTo jumpSUNS
:: Unsorted
DSQUERY USER %$AD_BASE% -scope %$AD_SCOPE% -o rdn -name "%$SEARCH_KEY%" -limit %$sLimit% %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% > "%$LogPath%\cache\var_Last_Search_N.txt"
DSQUERY USER %$AD_BASE% -scope %$AD_SCOPE% -o dn -name "%$SEARCH_KEY%" -limit %$sLimit% %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% > "%$LogPath%\cache\var_Last_Search_DN.txt"
GoTo skipSUNS
:jumpSUNS
:: Sorted
DSQUERY USER %$AD_BASE% -scope %$AD_SCOPE% -o rdn -name "%$SEARCH_KEY%" -limit %$sLimit% %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% | sort > "%$LogPath%\cache\var_Last_Search_N.txt"
DSQUERY USER %$AD_BASE% -scope %$AD_SCOPE% -o dn -name "%$SEARCH_KEY%" -limit %$sLimit% %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% | sort > "%$LogPath%\cache\var_Last_Search_DN.txt"
:skipSUNS
:: Check results
FOR /F "tokens=3 delims=:" %%K IN ('FIND /I /C "=" "%$LogPath%\cache\var_Last_Search_DN.txt"') DO echo %%K> "%$LogPath%\cache\var_Last_Search_Count.txt"
:: remove leading space
FOR /F "tokens=1 delims= " %%P IN (%$LogPath%\cache\var_Last_Search_Count.txt) DO echo %%P> "%$LogPath%\cache\var_Last_Search_Count.txt"
SET /P $LAST_SEARCH_COUNT= < "%$LogPath%\cache\var_Last_Search_Count.txt"
call :SM
IF %$LAST_SEARCH_COUNT% EQU 0 (
echo Number of search results: %$LAST_SEARCH_COUNT% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo End search: %DATE% %Time% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
TYPE "%$LogPath%\%$LAST_SEARCH_LOG%" >> "%$SEARCH_SESSION_LOG%"
@powershell Write-Host "Nothing found! Try again with broader wildcard" -ForegroundColor Red
GoTo skipSUN
)
:: Main output
echo Number of search results: %$LAST_SEARCH_COUNT% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Number of search results: %$LAST_SEARCH_COUNT%
@powershell Write-Host "Processing..." -ForegroundColor DarkYellow
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo User Names returned: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
type "%$LogPath%\cache\var_Last_Search_N.txt" >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo User Distinguisged Names: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
type "%$LogPath%\cache\var_Last_Search_DN.txt" >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
IF %$SUPPRESS_VERBOSE% EQU 1 GoTo jumpSUNO
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Verbose Output: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
:: Detailed Output
FOR /F "USEBACKQ tokens=* delims=" %%N IN ("%$LogPath%\cache\var_Last_Search_DN.txt") DO (
call :SM
@powershell Write-Host "Processing verbose..." -ForegroundColor DarkYellow
@powershell Write-Host '%%N' -ForegroundColor DarkGray
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr name userPrincipalName displayName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr sn givenName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo User DN: %%N >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Organization Information: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr company %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr department %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr title %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr description %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr manager %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Contact Information: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr mail %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr telephoneNumber %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Location Information: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr physicalDeliveryOfficeName streetAddress l st postalCode co %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Details: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr * %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
)
:jumpSUNO
:: Search counter increment
Call :fSC
:: Total Lapse TIme
call :subTLT
:: Refresh HUD
call :SM
echo Total Search Time: %$TOTAL_LAPSE_TIME%
echo Total Search Time: %$TOTAL_LAPSE_TIME% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo End search: %DATE% %Time% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
type "%$LogPath%\%$LAST_SEARCH_LOG%" >> "%$LogPath%\%$SEARCH_SESSION_LOG%"
:: Open log files
@explorer "%$LogPath%\%$LAST_SEARCH_LOG%"
:skipSUN
echo Search User Again?
Choice /c YN /m "[Y]es or [N]o":
IF %ERRORLEVEL% EQU 2 GoTo sUser
IF %ERRORLEVEL% EQU 1 GoTo SUN
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::: Search User UPN :::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SUU
SET $SEARCH_ATTRIBUTE=UPN
SET $SEARCH_KEY=
SET $LAST_SEARCH_COUNT=
:: Last Search Log Close - Notepad
call :LSLCN
call :SM
:: Console output
@powershell Write-Host "Attribute: UPN" -ForegroundColor Blue
@powershell Write-Host "Can use "*" wildcard for search." -ForegroundColor Gray
@powershell Write-Host "If left blank, will abort." -ForegroundColor Magenta
SET /P $SEARCH_KEY=User upn search key:
IF NOT DEFINED $SEARCH_KEY GoTo sUser
call :SM
echo Selected {%$SEARCH_KEY%} as upn search key.
@powershell Write-Host "Searching..." -ForegroundColor DarkYellow
:: Start Elapse Time
call :subSET
:: Write log headers
call :sHeader
:: Credentials
:: Domain credentials default to blank
SET $DOMAIN_CREDENTIALS=
if not "%$SESSION_USER%"=="%$DOMAIN_USER%" SET "$DOMAIN_CREDENTIALS=-u %$DOMAIN_USER% -p %$cUSERPASSWORD%"
REM If Forestroot, then searches GC Global Catalog.
set "$AD_SERVER_SEARCH=-s %$DC%.%$DOMAIN%"
if %$AD_BASE%==forestroot SET "$AD_SERVER_SEARCH=-gc"
:: Debug
if %$DEGUB_MODE% EQU 1 CALL :fVarD
:: Check for sorted
if %$SORTED% EQU 1 GoTo jumpSUUS
:: Unsorted
DSQUERY USER %$AD_BASE% -scope %$AD_SCOPE% -o rdn -upn "%$SEARCH_KEY%" -limit %$sLimit% %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% > "%$LogPath%\cache\var_Last_Search_N.txt"
DSQUERY USER %$AD_BASE% -scope %$AD_SCOPE% -o dn -upn "%$SEARCH_KEY%" -limit %$sLimit% %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% > "%$LogPath%\cache\var_Last_Search_DN.txt"
GoTo skipSUUS
:jumpSUUS
:: Sorted
DSQUERY USER %$AD_BASE% -scope %$AD_SCOPE% -o rdn -upn "%$SEARCH_KEY%" -limit %$sLimit% %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% | sort > "%$LogPath%\cache\var_Last_Search_N.txt"
DSQUERY USER %$AD_BASE% -scope %$AD_SCOPE% -o dn -upn "%$SEARCH_KEY%" -limit %$sLimit% %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% | sort > "%$LogPath%\cache\var_Last_Search_DN.txt"
:skipSUUS
:: Check results
FOR /F "tokens=3 delims=:" %%K IN ('FIND /I /C "=" "%$LogPath%\cache\var_Last_Search_DN.txt"') DO echo %%K> "%$LogPath%\cache\var_Last_Search_Count.txt"
:: remove leading space
FOR /F "tokens=1 delims= " %%P IN (%$LogPath%\cache\var_Last_Search_Count.txt) DO echo %%P> "%$LogPath%\cache\var_Last_Search_Count.txt"
SET /P $LAST_SEARCH_COUNT= < "%$LogPath%\cache\var_Last_Search_Count.txt"
call :SM
IF %$LAST_SEARCH_COUNT% EQU 0 (
echo Number of search results: %$LAST_SEARCH_COUNT% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo End search: %DATE% %Time% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
TYPE "%$LogPath%\%$LAST_SEARCH_LOG%" >> "%$SEARCH_SESSION_LOG%"
@powershell Write-Host "Nothing found! Try again with broader wildcard" -ForegroundColor Red
GoTo skipSUU
)
:: Main output
echo Number of search results: %$LAST_SEARCH_COUNT% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Number of search results: %$LAST_SEARCH_COUNT%
@powershell Write-Host "Processing..." -ForegroundColor DarkYellow
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo User Names returned: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
type "%$LogPath%\cache\var_Last_Search_N.txt" >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo User Distinguisged Names: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
type "%$LogPath%\cache\var_Last_Search_DN.txt" >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
IF %$SUPPRESS_VERBOSE% EQU 1 GoTo jumpSUUO
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Verbose Output: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
:: Detailed Output
FOR /F "USEBACKQ tokens=* delims=" %%N IN ("%$LogPath%\cache\var_Last_Search_DN.txt") DO (
call :SM
@powershell Write-Host "Processing verbose..." -ForegroundColor DarkYellow
@powershell Write-Host '%%N' -ForegroundColor DarkGray
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr name cn userPrincipalName displayName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr sn givenName %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo User DN: %%N >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Organization Information: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr company %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr department %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr title %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr description %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr manager %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Contact Information: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr mail %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr telephoneNumber %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Location Information: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr physicalDeliveryOfficeName streetAddress l st postalCode co %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo Details: >> "%$LogPath%\%$LAST_SEARCH_LOG%"
DSQUERY * %$AD_BASE% -scope %$AD_SCOPE% -limit %$sLimit% -filter "(&(objectClass=user)(distinguishedName=%%~N))" -attr * %$AD_SERVER_SEARCH% %$DOMAIN_CREDENTIALS% >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo ---------------------------------------------------------------------- >> "%$LogPath%\%$LAST_SEARCH_LOG%"
echo. >> "%$LogPath%\%$LAST_SEARCH_LOG%"
)
:jumpSUUO
:: Search counter increment
Call :fSC
:: Total Lapse TIme
call :subTLT
:: Refresh HUD
call :SM
echo Total Search Time: %$TOTAL_LAPSE_TIME%