-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDDC2.ps1
More file actions
2882 lines (2815 loc) · 157 KB
/
Copy pathDDC2.ps1
File metadata and controls
2882 lines (2815 loc) · 157 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<#
DCS Controller Script for Node-Red & Discord Interaction
# Version 2.3 Charlie
# Writen by OzDeaDMeaT
# 07-08-2025
Copyright (c) 2021 Josh 'OzDeaDMeaT' McDougall, All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
4. Utilization of this software for commercial use is prohibited unless authorized by the software copywrite holder in writing (electronic mail).
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#########################################################################################################
#ToDo####################################################################################################
#########################################################################################################
1. Setup Database Tools (create folder specified in ddc2_config.ps1)
2. Explore Pipleline Function integration
#########################################################################################################
#CHANGE LOG##############################################################################################
#########################################################################################################
- v2.2l Changed Start-DCS to allow for modification of MissionScripting.lua prior to DCS execution
- v2.2i Added new DDC2_Config settings to be loaded into Node-Red (scheduled task Reboot & Enable InfluxDB)
- v2.2h Tweaked Fix-Position so that it runs more efficiently
- v2.2g Added Fix-Position functions for Window Positioning in the event that the system didnt reposition correctly when DCS was loaded
- v2.2f Cleaned up Script Variables
- v2.2e Updated write-log function
- v2.2d Added more Tools for Firewall setup
- v2.2c Updated Firewall Functions
- v2.2b Updated Created a Functions section in DDC2.ps1 for Tool Functions.
- v2.2A Added Bidirectional Chat Capability (initial) between DDC2 and DCS
- v2.1A Added DDC2 Listening Port for data collection from DCS
- v2.0k Removed need for DDC2DIR to be declared when script is run.
- v2.0j Added DDC2-AutoStart
- v2.0j Added Add-Position
- v2.0j Added Set-Position
- v2.0j Updated Set-Window
- v2.0j Updated UPDATE-MOOSE
- v2.0i Changed PwdRandomizer to distinguish between SRS and DCS so PwdRandomizer could be called directly from application specific Start Command (start-dcs, start-srs)
- v2.0i Added Start-Server
- v2.0i Added Set-Priority
- v2.0i Added Wait-For-Response
- v2.0f Fixed Stop-SRS from closing all instances of SRS
- v2.0f Re-purposed Start-DCS
- v2.0f Added Start-SRS
##########################################################################################################>
param(
[switch]$init,
[switch]$AutoStart,
[switch]$Refresh,
[switch]$Radio,
[switch]$Update,
[switch]$Status,
[switch]$Start,
[switch]$Stop,
[switch]$StopAll,
[switch]$StopGame,
[switch]$StopDCS,
[switch]$StopSRS,
[switch]$StopUpdate,
[switch]$Restart,
[switch]$Reboot,
[switch]$Secure,
[switch]$Access,
[switch]$VNC,
[switch]$ClearAll,
[switch]$DoUpdate,
[switch]$LoadTools,
[string]$IP,
[string]$USER,
[string]$ID,
[string]$RadioMSG,
[string]$RadioFrq,
[string]$RadioMod,
[string]$RadioPort,
[string]$RadioSide,
[string]$RadioUser
)
#########################################################################################################
## ANY MODIFICATIONS BELOW THIS LINE ARE NOT SUPPORTED###################################################
#########################################################################################################
#Global Variables for Data Output and Process Selection set
$DCSreturn = $null
$DCSreturnJSON = $null
$selection = 'Name', 'id', 'ProcessName', 'PriorityClass', 'ProductVersion', 'Responding', 'StartTime', @{Name='Ticks';Expression={$_.TotalProcessorTime.Ticks}}, @{Name='MemGB';Expression={'{00:N2}' -f ($_.WS/1GB)}}
$ProcessSelection = 'id', 'PriorityClass', 'ProductVersion', 'Responding', 'StartTime', @{Name='Ticks';Expression={$_.TotalProcessorTime.Ticks}}, @{Name='MemGB';Expression={'{00:N2}' -f ($_.WS/1GB)}}, 'MainWindowTitle', 'Path'
$DDC2_PSCore_Version = "v2.3 Charlie"
$PosArray = [PSCustomObject]@{}
####################################################################################################
##This section Sets the DDC2 Location for execution and sets the correct config and log files to write to.
$DDC2DIR = Split-Path $MyInvocation.MyCommand.Definition -Parent
$DDC2_LogFile = "$DDC2DIR\DDC2.log" #Log File Location for this script
$DDC2_Config = "$DDC2DIR\ddc2_config.ps1" #DDC2 Configuration and Settings File Location
$DDC2_File = "$DDC2DIR\ddc2.ps1" #DDC2 File Location
####################################################################################################
# .----------------. .----------------. .----------------. .----------------. .----------------.
#| .--------------. | | .--------------. | | .--------------. | | .--------------. | | .--------------. |
#| | _________ | | | | ____ | | | | ____ | | | | _____ | | | | _______ | |
#| | | _ _ | | | | | .' `. | | | | .' `. | | | | |_ _| | | | | / ___ | | |
#| | |_/ | | \_| | | | | / .--. \ | | | | / .--. \ | | | | | | | | | | | (__ \_| | |
#| | | | | | | | | | | | | | | | | | | | | | | | | | _ | | | | '.___`-. | |
#| | _| |_ | | | | \ `--' / | | | | \ `--' / | | | | _| |__/ | | | | | |`\____) | | |
#| | |_____| | | | | `.____.' | | | | `.____.' | | | | |________| | | | | |_______.' | |
#| | | | | | | | | | | | | | | | | | | |
#| '--------------' | | '--------------' | | '--------------' | | '--------------' | | '--------------' |
# '----------------' '----------------' '----------------' '----------------' '----------------'
#########################################################################################################
Function Out-Report {
param(
[Parameter(Mandatory=$true)][string]$Label,
$Data,
[string]$LabelColour = "white",
[string]$DataColour = "yellow",
[switch]$CheckPath,
[switch]$Bool #Do not use CheckPath and Bool at the same time
)
[string]$CheckOK = "green"
[string]$CheckDisabled = "yellow"
[string]$CheckFail = "red"
write-host "$Label " -foregroundcolor $LabelColour -nonewline
if($CheckPath) {
if($Data -eq "") {$Data = "NOT CONFIGURED"}
$check = test-path $Data -ErrorAction SilentlyContinue
if ($check) {
write-host "OK" -ForegroundColor $CheckOK -nonewline
write-host " - $Data" -ForegroundColor $DataColour
} else {
write-host "Not Found" -ForegroundColor $CheckFail -nonewline
write-host " - $Data" -ForegroundColor $DataColour
}
} ElseIf ($Bool){
if($data -eq $true) {
write-host "Enabled" -ForegroundColor $CheckOK
} else {
write-host "Disabled" -ForegroundColor $CheckDisabled
}
} else {
if($Data -eq "") {
$Data = "NOT CONFIGURED"
write-host $Data -foregroundcolor $CheckFail
} else {
write-host $Data -foregroundcolor $CheckOK
}
}
}
if($LoadTools) {
write-host " LOADING DDC2 TOOLS" -foregroundcolor "white"
write-host " "
Out-Report -Label "Out-Report :" -Data 1 -Bool}
#########################################################################################################
Function Write-Log {
<#
.Version 2
Added foregroundcolor passthru as well as nonewline passthru
.DESCRIPTION
Write-Log is a simple function that dumps an output to a log file.
.EXAMPLE
The line below will create a log file called test.log in the current folder and populate it with 'This data is going into the log'
write-log -LogData "This data is going into the log" -LogFile "test.log"
#>
Param (
$LogData = "",
$LogFile = $DDC2_LogFile,
$foregroundcolor = ($Host.UI.RawUI).ForegroundColor,
[switch]$nonewline,
[switch]$Silent
)
if ($LogData -ne "") {
$Time = get-date -Format "yyyy-MMM-dd--HH:mm:ss"
$TimeStampLog = $Time + " - " + $LogData
if (-Not (test-path $LogFile)) {
$shh = new-item $LogFile -type File -Force -ErrorAction SilentlyContinue
if($shh.count -gt 0) {
$created = $Time + " - LOGFILE CREATED"
Add-Content $LogFile $created
Add-Content $LogFile $TimeStampLog
if(-not ($silent)) {
write-host "LOGFILE CREATED" -foregroundcolor $foregroundcolor
if($nonewline) {write-host $LogData -foregroundcolor $foregroundcolor -nonewline} else {write-host $LogData -foregroundcolor $foregroundcolor}
}
}
else
{
if(-not ($silent)) {
write-host "Logfile does not exist and was not able to be created, please check path provided and try again"
}
}
}
else
{
Add-Content $LogFile $TimeStampLog
if(-not ($silent)) {
if($nonewline) {write-host $LogData -foregroundcolor $foregroundcolor -nonewline} else {write-host $LogData -foregroundcolor $foregroundcolor}
}
}
}
}
if($LoadTools) {Out-Report -Label "Write-Log :" -Data 1 -Bool}
####################################################################################################
Function Prompt-User {
<#
.DESCRIPTION
Prompt-User allows for a simple user prompt based on Parameters passed to it.
#Note: The Default Option is always true. So if you use the switch -NoAsDefault it will make the return of 'no' as True. Its annoying and confusing but it is the way this Automation Host thing works. :(
.EXAMPLE
Prompt-User -Question "Is DDC2 Awesome?!?" -NoHelp "You shouldn't lie, lying is back" -YesHelp "Damn Right it is"
Prompt-User -Question "Did you poop yourself?" -NoHelp "No, it was just an epic fart!" -YesHelp "Yes, it's what all the kids are doing these days, it's hip and happening!" -NoAsDefault
#>
param(
[Parameter(Mandatory=$true)][string]$Question,
[Parameter(Mandatory=$true)][string]$NoHelp,
[Parameter(Mandatory=$true)][string]$YesHelp,
[switch]$NoAsDefault
)
$DefaultOption = if($NoAsDefault) {1} else {0}
$yes = New-Object System.Management.Automation.Host.ChoiceDescription ("&Yes", $YesHelp)
$no = New-Object System.Management.Automation.Host.ChoiceDescription ("&No", $NoHelp)
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$rtn = $Host.ui.PromptForChoice("", $Question, $options, $DefaultOption)
return $rtn
}
if($LoadTools) {Out-Report -Label "Prompt-User :" -Data 1 -Bool}
#########################################################################################################
Function Add-Position {
param(
[Parameter(Mandatory=$true)]$POSid,
[Parameter(Mandatory=$true)]$SRS_X,
[Parameter(Mandatory=$true)]$SRS_Y,
[Parameter(Mandatory=$true)]$DCS_X,
[Parameter(Mandatory=$true)]$DCS_Y,
[Parameter(Mandatory=$true)]$DCS_SizeX,
[Parameter(Mandatory=$true)]$DCS_SizeY
)
$NewItem = @(
[pscustomobject]@{`
POSid = $POSid;`
SRS_X = $SRS_X;`
SRS_Y = $SRS_Y;`
DCS_X = $DCS_X;`
DCS_Y = $DCS_Y;`
DCS_SizeX = $DCS_SizeX;`
DCS_SizeY = $DCS_SizeY}
)
return $PosArray + $NewItem
}
if($LoadTools) {Out-Report -Label "Add-Position :" -Data 1 -Bool}
####################################################################################################
Function Set-Position {
param(
[Parameter(Mandatory=$true)]$Id,
[switch]$DCS,
[switch]$SRS
)
If($DesktopLocation -lt $PosArray.Count) {
If($SRS) {
$locationArray = $PosArray[$DesktopLocation]
Set-Window -Id $Id -x $locationArray.SRS_X -y $locationArray.SRS_Y
write-log -LogData "SRS Window with ProcessID: $Id has been moved to Desktop Position #$DesktopLocation" -Silent
}
If($DCS) {
$locationArray = $PosArray[$DesktopLocation]
Set-Window -Id $Id -x $locationArray.DCS_X -y $locationArray.DCS_Y -Width $locationArray.DCS_SizeX -Height $locationArray.DCS_SizeY
write-log -LogData "DCS Window with ProcessID: $Id has been moved to Desktop Position #$DesktopLocation" -Silent
}
} else {write-log -LogData 'Invalid configurtation for $DesktopLocation, the LocationID given is greater than the array of locations available' -Silent}
}
if($LoadTools) {Out-Report -Label "Set-Position :" -Data 1 -Bool}
####################################################################################################
Function Check-DDC2 {
<#
.DESCRIPTION
Version 2 of Check-DDC2 Function. This function checks that all the config files etc have been entered correctly into the DDC2 Powershell script
.EXAMPLE
Check-DDC2
#>
write-host "Reloading DDC2.ps1 file into memory..." -ForegroundColor "white"
. .\DDC2.ps1
write-host " "
write-host "Checking DDC2 & System Variables..." -ForegroundColor "white"
Out-Report -Label "`$ServerID ==" -Data $ServerID
Out-Report -Label "`$ServerDT ==" -Data $ServerDT
Out-Report -Label "`$DDC2_MASTER ==" -Data $DDC2_MASTER
Out-Report -Label "`$DDC2_CommandPrefix ==" -Data $DDC2_CommandPrefix
Out-Report -Label "`$DDC2_HELP ==" -Data $DDC2_HELP -Bool
Out-Report -Label "`$DDC2_LINK_MASTER ==" -Data $DDC2_LINK_MASTER -Bool
Out-Report -Label "`$DCSBETA ==" -Data $DCSBETA -Bool
Out-Report -Label "`$SRSBETA ==" -Data $SRSBETA -Bool
Out-Report -Label "`$LoTBETA ==" -Data $LoTBETA -Bool
Out-Report -Label "`$UPDATE_DCS ==" -Data $UPDATE_DCS -Bool
Out-Report -Label "`$UPDATE_SRS ==" -Data $UPDATE_SRS -Bool
Out-Report -Label "`$UPDATE_LoT ==" -Data $UPDATE_LoT -Bool
Out-Report -Label "`$UPDATE_MOOSE ==" -Data $UPDATE_MOOSE -Bool
Out-Report -Label "`$AutoStartonUpdate ==" -Data $AutoStartonUpdate -Bool
Out-Report -Label "`$ACCESS_LOOP_DELAY ==" -Data $ACCESS_LOOP_DELAY
Out-Report -Label "`$UPDATE_LOOP_DELAY ==" -Data $UPDATE_LOOP_DELAY
Out-Report -Label "`$VNCEnabled ==" -Data $VNCEnabled -Bool
Out-Report -Label "`$VNC_Path ==" -Data $VNC_Path -CheckPath
Out-Report -Label "`$DDC2_LogFile ==" -Data $DDC2_LogFile -CheckPath
Out-Report -Label "`$DDC2_Hooks_Log ==" -Data $DDC2_Hooks_Log -CheckPath
Out-Report -Label "`$DDC2_File ==" -Data $DDC2_File -CheckPath
Out-Report -Label "`$DDC2_Config ==" -Data $DDC2_Config -CheckPath
Out-Report -Label "`$DDC2_Hooks ==" -Data $DDC2_Hooks -CheckPath
Out-Report -Label "`$VNCPort ==" -Data $VNCPort
Out-Report -Label "`$VNCType ==" -Data $VNCType
Out-Report -Label "`$HostedByMember ==" -Data $HostedByMember -Bool
Out-Report -Label "`$HostedByName ==" -Data $HostedByName
Out-Report -Label "`$HostedAT ==" -Data $HostedAT
Out-Report -Label "`$DiscordID ==" -Data $DiscordID
Out-Report -Label "`$SupportByMember ==" -Data $SupportByMember -Bool
Out-Report -Label "`$SupportContactID ==" -Data $SupportContactID
Out-Report -Label "`$SupportBy ==" -Data $SupportBy
Out-Report -Label "`$SupportTimeTXT ==" -Data $SupportTimeTXT
Out-Report -Label "`$SupportContactTXT ==" -Data $SupportContactTXT
Out-Report -Label "`$ISP ==" -Data $ISP
Out-Report -Label "`$DNSName ==" -Data $DNSName
write-host " "
write-host "Checking DDC2 - Password Settings..." -ForegroundColor "white"
Out-Report -Label "`$EnableRandomizer ==" -Data $EnableRandomizer -Bool
Out-Report -Label "`$ServerPassword ==" -Data $ServerPassword -Bool
Out-Report -Label "`$SRSPassword ==" -Data $SRSPassword -Bool
Out-Report -Label "`$SeperateLOT ==" -Data $SeperateLOT -Bool
Out-Report -Label "`$SeperateTAC ==" -Data $SeperateTAC -Bool
Out-Report -Label "`$SHOW_BLUPWD ==" -Data $SHOW_BLUPWD -Bool
Out-Report -Label "`$SHOW_REDPWD ==" -Data $SHOW_REDPWD -Bool
Out-Report -Label "`$SHOW_SRVPWD ==" -Data $SHOW_SRVPWD -Bool
Out-Report -Label "`$SHOW_LotATC ==" -Data $SHOW_LotATC -Bool
Out-Report -Label "`$SHOW_TACView ==" -Data $SHOW_TACView -Bool
write-host " "
write-host "Checking DDC2 - Notification Settings..." -ForegroundColor "white"
Out-Report -Label "`$ENABLE_NOTIFY ==" -Data $ENABLE_NOTIFY -Bool
Out-Report -Label "`$FRIENDLY_FIRE ==" -Data $FRIENDLY_FIRE -Bool
Out-Report -Label "`$MISSION_END ==" -Data $MISSION_END -Bool
Out-Report -Label "`$KILL ==" -Data $KILL -Bool
Out-Report -Label "`$SELF_KILL ==" -Data $SELF_KILL -Bool
Out-Report -Label "`$CHANGE_SLOT ==" -Data $CHANGE_SLOT -Bool
Out-Report -Label "`$CONNECT ==" -Data $CONNECT -Bool
Out-Report -Label "`$DISCONNECT ==" -Data $DISCONNECT -Bool
Out-Report -Label "`$CRASH ==" -Data $CRASH -Bool
Out-Report -Label "`$EJECT ==" -Data $EJECT -Bool
Out-Report -Label "`$TAKEOFF ==" -Data $TAKEOFF -Bool
Out-Report -Label "`$LANDING ==" -Data $LANDING -Bool
Out-Report -Label "`$PILOT_DEATH ==" -Data $PILOT_DEATH -Bool
write-host " "
write-host "Checking DDC2 - DCS Variables..." -ForegroundColor "white"
Out-Report -Label "`$DCS_Profile ==" -Data $DCS_Profile -CheckPath
Out-Report -Label "`$DCS_Config ==" -Data $DCS_Config -CheckPath
Out-Report -Label "`$DCS_AutoE ==" -Data $DCS_AutoE -CheckPath
Out-Report -Label "`$dcsDIR ==" -Data $dcsDIR -CheckPath
Out-Report -Label "`$dcsBIN ==" -Data $dcsBIN -CheckPath
Out-Report -Label "`$dcsEXE ==" -Data $dcsEXE -CheckPath
Out-Report -Label "`$dcsargs ==" -Data $dcsargs
Out-Report -Label "`$DCS_WindowTitle ==" -Data $DCS_WindowTitle
Out-Report -Label "`$DCS_Updater ==" -Data $DCS_Updater -CheckPath
Out-Report -Label "`$DCS_Updater_Args ==" -Data $DCS_Updater_Args
write-host " "
write-host "Checking DDC2 - SRS Variables..." -ForegroundColor "white"
Out-Report -Label "`$srsDIR ==" -Data $srsDIR -CheckPath
Out-Report -Label "`$srsEXE ==" -Data $srsEXE -CheckPath
Out-Report -Label "`$SRS_External ==" -Data $SRS_External -CheckPath
Out-Report -Label "`$SRS_Clients ==" -Data $SRS_Clients -CheckPath
Out-Report -Label "`$SRS_Config ==" -Data $SRS_Config -CheckPath
Out-Report -Label "`$SRS_Updater ==" -Data $SRS_Updater -CheckPath
Out-Report -Label "`$SRS_AutoConnect ==" -Data $SRS_AutoConnect -CheckPath
Out-Report -Label "`$SRSargs ==" -Data $SRSargs
Out-Report -Label "`$srsCLIENTSFile ==" -Data $srsCLIENTSFile
Out-Report -Label "`$srsCONFIGFile ==" -Data $srsCONFIGFile
Out-Report -Label "`$SRS_Updater_Args ==" -Data $SRS_Updater_Args
Out-Report -Label "`$SRS_FreqLOW ==" -Data $SRS_FreqLOW
Out-Report -Label "`$SRS_FreqHIGH ==" -Data $SRS_FreqHIGH
Out-Report -Label "`$SRS_DefaultMOD ==" -Data $SRS_DefaultMOD
Out-Report -Label "`$SRS_DefaultVOL ==" -Data $SRS_DefaultVOL
Out-Report -Label "`$SRS_DefaultCoal ==" -Data $SRS_DefaultCoal
write-host " "
write-host "Checking DDC2 - LoTATC Variables..." -ForegroundColor "white"
Out-Report -Label "`$LotDIR ==" -Data $LotDIR -CheckPath
Out-Report -Label "`$Lot_Entry ==" -Data $Lot_Entry -CheckPath
Out-Report -Label "`$Lot_Config ==" -Data $Lot_Config -CheckPath
Out-Report -Label "`$Lot_Updater ==" -Data $Lot_Updater -CheckPath
Out-Report -Label "`$Lot_Updater_Args ==" -Data $Lot_Updater_Args
write-host " "
write-host "Checking DDC2 - TacView Variables..." -ForegroundColor "white"
Out-Report -Label "`$TacvDIR ==" -Data $TacvDIR -CheckPath
Out-Report -Label "`$TacvEXE ==" -Data $TacvEXE -CheckPath
Out-Report -Label "`$TACv_Entry ==" -Data $TACv_Entry -CheckPath
Out-Report -Label "`$TACv_Config ==" -Data $TACv_Config -CheckPath
write-host " "
write-host "Checking DDC2 - DataBase Variables..." -ForegroundColor "white"
Out-Report -Label "`$DB_File ==" -Data $DB_File -CheckPath
Out-Report -Label "`$DB_Server ==" -Data $DB_Server
write-host " "
write-host "Checking DDC2 - Discord Channels..." -ForegroundColor "white"
Out-Report -Label "`$AdminChannel ==" -Data $AdminChannel
Out-Report -Label "`$BlueChannel ==" -Data $BlueChannel
Out-Report -Label "`$RedChannel ==" -Data $RedChannel
Out-Report -Label "`$LogChannel ==" -Data $LogChannel
Out-Report -Label "`$SupportChannel ==" -Data $SupportChannel
Out-Report -Label "`$ServerStatusChannel==" -Data $ServerStatusChannel
write-host " "
write-host "Checking DDC2 - Command Permissions..." -ForegroundColor "white"
Out-Report -Label "`$testPerm ==" -Data $testPerm
Out-Report -Label "`$versionPerm ==" -Data $versionPerm
Out-Report -Label "`$infoPerm ==" -Data $infoPerm
Out-Report -Label "`$supportPerm ==" -Data $supportPerm
Out-Report -Label "`$helpPerm ==" -Data $helpPerm
Out-Report -Label "`$radioPerm ==" -Data $radioPerm
Out-Report -Label "`$startPerm ==" -Data $startPerm
Out-Report -Label "`$stopPerm ==" -Data $stopPerm
Out-Report -Label "`$restartPerm ==" -Data $restartPerm
Out-Report -Label "`$statusPerm ==" -Data $statusPerm
Out-Report -Label "`$refreshPerm ==" -Data $refreshPerm
Out-Report -Label "`$portsPerm ==" -Data $portsPerm
Out-Report -Label "`$configPerm ==" -Data $configPerm
Out-Report -Label "`$updatePerm ==" -Data $updatePerm
Out-Report -Label "`$accessPerm ==" -Data $accessPerm
Out-Report -Label "`$rebootPerm ==" -Data $rebootPerm
Out-Report -Label "`$acclinkPerm ==" -Data $acclinkPerm
write-host "DDC2 Check Report..." -ForegroundColor "white" -nonewline
write-host "COMPLETE!" -ForegroundColor "green"
}
if($LoadTools) {Out-Report -Label "Check-DDC2 :" -Data 1 -Bool}
####################################################################################################
Function Check-Ports {
<#
.DESCRIPTION
This function checks all the config files defined in ddc2_config.ps1 for port information and displays the ports in an easy to read manner.
.EXAMPLE
Check-Ports
#>
write-host " "
write-host "Checking ports for DDC2-ID: $ServerID, installed in $DDC2DIR" -ForegroundColor white
write-host " "
if(test-path $DCS_Config) {
write-host "Port Configuration from - " -ForegroundColor white -nonewline
write-host "$DCS_Config" -ForegroundColor green
$DCS_PORT = ((Select-String -Path $DCS_Config -Pattern "port" | Out-String).Split(' ')[-1]).Split(',')[0]
write-host " : port = " -nonewline
write-host "$DCS_PORT" -ForegroundColor green
} else {
write-host 'Port Configuration from - ' -ForegroundColor white -nonewline
write-host '$DCS_Config file path not found (check ddc2_config.ps1)' -ForegroundColor yellow
}
write-host " "
if(test-path $SRS_AutoConnect) {
write-host "Port Configuration from - " -ForegroundColor white -nonewline
write-host "$SRS_AutoConnect" -ForegroundColor green
$SRS_SERVER_SRS_PORT = (Select-String -Path $SRS_AutoConnect -Pattern "SRSAuto.SERVER_SRS_PORT =" | Out-String).Split('"')[-2]
write-host " : SRSAuto.SERVER_SRS_PORT = " -nonewline
write-host "$SRS_SERVER_SRS_PORT" -ForegroundColor green
} else {
write-host 'Port Configuration from - ' -ForegroundColor white -nonewline
write-host '$SRS_AutoConnect file path not found (check ddc2_config.ps1)' -ForegroundColor yellow
}
write-host " "
if(test-path $SRS_Config) {
write-host "Port Configuration from - " -ForegroundColor white -nonewline
write-host "$SRS_Config" -ForegroundColor green
$SRS_SERVER_PORT = ((Select-String -Path $SRS_Config -Pattern "SERVER_PORT" | Out-String).Split('=')[1]).Trim()
write-host " : SERVER_PORT = " -nonewline
write-host "$SRS_SERVER_PORT" -ForegroundColor green
$SRS_LOTATC_EXPORT_PORT = ((Select-String -Path $SRS_Config -Pattern "LOTATC_EXPORT_PORT" | Out-String).Split('=')[1]).Trim()
write-host " : LOTATC_EXPORT_PORT = " -nonewline
write-host "$SRS_LOTATC_EXPORT_PORT" -ForegroundColor green
} else {
write-host 'Port Configuration from - ' -ForegroundColor white -nonewline
write-host '$SRS_Config file path not found (check ddc2_config.ps1)' -ForegroundColor yellow
}
write-host " "
if(test-path $DCS_AutoE) {
write-host "Port Configuration from - " -ForegroundColor white -nonewline
write-host "$DCS_AutoE" -ForegroundColor green
$DCS_webgui_port = ((Select-String -Path $DCS_AutoE -Pattern "webgui_port " | Out-String).Split('=')[-1]).Trim()
write-host " : webgui_port = " -nonewline
write-host "$DCS_webgui_port" -ForegroundColor green
} else {
write-host 'Port Configuration from - ' -ForegroundColor white -nonewline
write-host '$DCS_AutoE file path not found (check ddc2_config.ps1)' -ForegroundColor yellow
write-host " : webgui_port = " -nonewline
write-host "8088 (DEFAULT)" -ForegroundColor yellow
}
write-host " "
if(test-path $Lot_Config) {
write-host "Port Configuration from - " -ForegroundColor white -nonewline
write-host "$Lot_Config" -ForegroundColor green
$LotATC_port = ((Select-String -Path $Lot_Config -Pattern " port =" | Out-String).Split(' ')[-1] | Out-String).Split(',')[0]
write-host " : port = " -nonewline
write-host "$LotATC_port" -ForegroundColor green
$LotATC_srs_transponder_port = ((Select-String -Path $Lot_Config -Pattern " srs_transponder_port =" | Out-String).Split(' ')[-1] | Out-String).Split(',')[0]
write-host " : srs_transponder_port = " -nonewline
write-host "$LotATC_srs_transponder_port" -ForegroundColor green
$LotATC_jsonserver_port = ((Select-String -Path $Lot_Config -Pattern " jsonserver_port =" | Out-String).Split(' ')[-1] | Out-String).Split(',')[0]
write-host " : jsonserver_port = " -nonewline
write-host "$LotATC_jsonserver_port" -ForegroundColor green
} else {
write-host 'Port Configuration from - ' -ForegroundColor white -nonewline
write-host '$Lot_Config file path not found (check ddc2_config.ps1)' -ForegroundColor yellow
}
write-host " "
if(test-path $TACv_Config) {
write-host "Port Configuration from - " -ForegroundColor white -nonewline
write-host "$TACv_Config" -ForegroundColor green
$TACv_tacviewRealTimeTelemetryPort = (Select-String -Path $TACv_Config -Pattern "tacviewRealTimeTelemetryPort" | Out-String).Split('"')[-2]
write-host " : tacviewRealTimeTelemetryPort = " -nonewline
write-host "$TACv_tacviewRealTimeTelemetryPort" -ForegroundColor green
$TACv_tacviewRemoteControlPort = (Select-String -Path $TACv_Config -Pattern "tacviewRemoteControlPort" | Out-String).Split('"')[-2]
write-host " : tacviewRemoteControlPort = " -nonewline
write-host "$TACv_tacviewRemoteControlPort" -ForegroundColor green
} else {
write-host 'Port Configuration from - ' -ForegroundColor white -nonewline
write-host '$TACv_Config file path not found (check ddc2_config.ps1)' -ForegroundColor yellow
}
}
if($LoadTools) {Out-Report -Label "Check-Ports :" -Data 1 -Bool}
####################################################################################################
Function Setup-Ports {
Param (
[Parameter(Mandatory=$true)][int]$DCSPort
)
<#
.DESCRIPTION
This Function will go through all the configuration files mentioned in DDC2_Config.ps1 and modify the ports accordingly.
Usage Process:
1. Stop DCS, SRS and any updates happening on your server
2. To get this function available in your Powershell browse to your DDC2 installation folder and execute: . .\ddc2.ps1
3. Make sure your ddc2_config.ps1 file has all the correct folders mapped for this specific instance of DCS and supporting Applications
#If not, fix the issues and then re execute: . .\ddc2.ps1
4. Follow example below.
5. Execute the !refresh command from inside discord and then !start your server or reboot your server
.EXAMPLE
Executing this: Setup-Ports -DCSPort 8881
This function sets up ports in accordance with a specific pattern listed below
$DCSPort = DCS World Port (8881)
$SRSPort = SRS Server Port + 1 (8882)
$LoTPort = LoTATC Port + 2 (8883)
$TACPort = TACView Client Telemetry Port + 3 (8884)
$WebUIPort = DCS Server WebUI Port + 4 (8885)
$ConsolePort = Console Port + 5 (Not configured by this Function) (8886)
$SRSTransponder = SRS Server Port + 6 (8887)
$TACRCPort = TACView RC Port + 7 (8888)
$LoTJSONPort = LoTATC JSON Server Port + 8 (8889)
#>
write-log "Setup-Ports: STARTED" -silent
if(test-path $DCS_Config) {
Set-Port -Search "[`"port`"]" -Port ($DCSPort+ 0) -File $DCS_Config
} else {
write-log "$DCS_Config File not Found"
}
if(test-path $SRS_Config) {
Set-Port -Search "SERVER_PORT" -Port ($DCSPort + 1) -File $SRS_Config
Set-Port -Search "LOTATC_EXPORT_PORT" -Port ($DCSPort + 6) -File $SRS_Config
} else {
write-log "$SRS_Config File not Found"
}
if(test-path $Lot_Config) {
Set-Port -Search " port =" -Port ($DCSPort + 2) -File $Lot_Config
Set-Port -Search "srs_transponder_port" -Port ($DCSPort + 6) -File $Lot_Config
Set-Port -Search "jsonserver_port" -Port ($DCSPort + 8) -File $Lot_Config
} else {
write-log "$Lot_Config File not Found"
}
if(test-path $TACv_Config) {
Set-Port -Search "[`"tacviewRealTimeTelemetryPort`"]" -Port ($DCSPort + 3) -File $TACv_Config
Set-Port -Search "[`"tacviewRemoteControlPort`"]" -Port ($DCSPort + 7) -File $TACv_Config
} else {
write-log "$TACv_Config File not Found"
}
if(test-path $DCS_AutoE) {
Set-Port -Search "webgui_port" -Port ($DCSPort + 4) -File $DCS_AutoE
} else {
write-log "$DCS_AutoE File not Found" -silent
}
if(test-path $SRS_AutoConnect) {
Set-Port -Search "SRSAuto.SERVER_SRS_PORT =" -Port ($DCSPort + 1) -File $SRS_AutoConnect
} else {
write-log "$SRS_AutoConnect File not Found" -silent
}
write-log "Setup-Ports: ENDED" -silent
}
if($LoadTools) {Out-Report -Label "Setup-Ports :" -Data 1 -Bool}
####################################################################################################
Function Disable-Default-RDP-Rules {
Param (
[switch]$Force
)
write-log -LogData "Disable-Default-RDP-Firewall-Rules Started" -silent
if($Force) {
$LeaveEnabled = $false
} else {
$LeaveEnabled = Prompt-User -Question "Are you sure you wish to disable the default RDP Firewall Rules?" -NoHelp "(No) This will not disable the default firewall rules for RDP" -YesHelp "(Yes) This WILL disable the default firewall rules for RDP. BE BLOODY SURE YOU WANT TO DO THIS!" -NoAsDefault
}
#NoAsDefault means No is True
if ($LeaveEnabled) {
write-log -LogData "User selected to leave default RDP rules enabled." -foregroundcolor "white"
} else {
write-log -LogData "Disabling Remote Desktop - Shadow (TCP-In)..." -foregroundcolor "white" -nonewline
Get-NetFirewallRule -DisplayName "Remote Desktop - Shadow (TCP-In)" | Disable-NetFirewallRule
write-log -LogData "DONE!" -foregroundcolor "green"
write-log -LogData "Disabling Remote Desktop - User Mode (TCP-In)..." -foregroundcolor "white" -nonewline
Get-NetFirewallRule -DisplayName "Remote Desktop - User Mode (TCP-In)" | Disable-NetFirewallRule
write-log -LogData "DONE!" -foregroundcolor "green"
write-log -LogData "Disabling Remote Desktop - User Mode (UDP-In)..." -foregroundcolor "white" -nonewline
Get-NetFirewallRule -DisplayName "Remote Desktop - User Mode (UDP-In)" | Disable-NetFirewallRule
write-log -LogData "DONE!" -foregroundcolor "green"
}
}
if($LoadTools) {Out-Report -Label "Disable-Default-RDP-Rules :" -Data 1 -Bool}
####################################################################################################
Function Finalize-Firewall-Rules {
Param (
[string]$WhiteListPrefix = '',
[switch]$RDP
)
$WhiteListPrefixAsterix = "*$WhiteListPrefix*"
write-log -LogData "Finalize-Firewall-Rules Started"
write-log -LogData "WhiteListPrefix = $WhiteListPrefix"
$RDPPath1 = "%SystemRoot%\system32\svchost.exe"
$RDPPath2 = "%SystemRoot%\system32\RdpSa.exe"
if($RDP) {write-log -LogData "Path = $RDPPath1 & $RDPPath2"
} else {write-log -LogData "Path = $Path"}
$Rules = @()
$RemoteAccessRules = Get-NetFirewallRule -Group "Remote Desktop"
Foreach($RArule in $RemoteAccessRules) {
$AppPath = $null
$AppPath = ($RArule | Get-NetFirewallApplicationFilter).AppPath
$RArule | Add-Member -MemberType NoteProperty -Name AppPath -Value $AppPath
If ($AppPath -like $RDPPath1) {
$RArule | Add-Member -MemberType NoteProperty -Name RDP -Value $true}
ElseIf ($AppPath -like $RDPPath2) {$RArule | Add-Member -MemberType NoteProperty -Name RDP -Value $true}
else {$RArule | Add-Member -MemberType NoteProperty -Name RDP -Value $false}
$Rules += $RArule
}
write-log -LogData "Searching for Firewall Rules..."
$EnableRules = @()
$DisableRules = @()
Foreach($rule in $Rules) {
if (($rule).DisplayName -like $WhiteListPrefixAsterix) {
$EnableRules += $rule
} else {
if($RDP -eq $rule.RDP) {$DisableRules += $rule}
}
}
if($EnableRules.Count -gt 0) {
$EnableCount = $EnableRules.Count
$DisableCount = $DisableRules.Count
write-log -LogData "Keeping $EnableCount Firewall Rules..."
Foreach ($eRule in $EnableRules) {
$eRule | Enable-NetFirewallRule
$Dname = $eRule.DisplayName
write-log -LogData "Enabling $Dname..."
}
write-log -LogData "Disabling $DisableCount Firewall Rules..."
Foreach ($dRule in $DisableRules) {
if($RDP -eq $dRule.RDP) {
$dRule | Disable-NetFirewallRule
$Dname = $dRule.DisplayName
write-log -LogData "Disabling $Dname..."
}
}
} else {
write-log -LogData "WARNING!! No Enabled Rules Detected!!"
}
}
if($LoadTools) {Out-Report -Label "Finalize-Firewall-Rules :" -Data 1 -Bool}
####################################################################################################
Function Setup-Firewall-RDPPort {
Param (
[string]$IP = ''
)
write-log -LogData "Setup-Firewall-RDPPort Started"
$RDPPort = (Get-Item "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp").GetValue('PortNumber')
$RULE_NAME_PREFIX = "RDP Port - $RDPPort --"
$Octet = '(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9]{2}|2[0-5][0-5]|2[0-4][0-9])'
[regex] $IPv4Regex = "^(?:$Octet\.){3}$Octet$"
$checkIP = $IP -match $IPv4Regex
if($CheckIP) {
#check if the rules currently exist
$currentRules = (get-NetFirewallRule -Name "$RULE_NAME_PREFIX *" | Measure-Object).count
if($currentRules -gt 0) {
get-NetFirewallRule -Name "$RULE_NAME_PREFIX *" | remove-NetFirewallRule
write-log -LogData "Old Firewall Rules Found, removing..." -Silent
Start-sleep 1
}
$shh = New-NetFirewallRule -Name "$RULE_NAME_PREFIX TCP" -DisplayName "$RULE_NAME_PREFIX TCP" -Description $RULE_DESCRIPTION -Direction Inbound -LocalPort $RDPPort -Protocol TCP -RemoteAddress $IP -Action Allow -Program %SystemRoot%\system32\svchost.exe -Group 'Remote Desktop'
$shh = New-NetFirewallRule -Name "$RULE_NAME_PREFIX UDP" -DisplayName "$RULE_NAME_PREFIX UDP" -Description $RULE_DESCRIPTION -Direction Inbound -LocalPort $RDPPort -Protocol UDP -RemoteAddress $IP -Action Allow -Program %SystemRoot%\system32\svchost.exe -Group 'Remote Desktop'
$hhh = New-NetFirewallRule -Name "$RULE_NAME_PREFIX Shadow TCP" -DisplayName "$RULE_NAME_PREFIX Shadow TCP" -Description $RULE_DESCRIPTION -Direction Inbound -Protocol TCP -RemoteAddress $IP -Action Allow -Program %SystemRoot%\system32\RdpSa.exe -Group 'Remote Desktop'
}
write-log -LogData "Setup-Firewall-RDPPort Finished"
}
if($LoadTools) {Out-Report -Label "Setup-Firewall-RDPPort :" -Data 1 -Bool}
####################################################################################################
Function Setup-Firewall-VNCPort {
Param (
[string]$IP = '',
[string]$Port,
[string]$Path = $VNC_Path
)
write-log -LogData "Setup-Firewall-VNCPort Started"
$Dtime = (get-date).DateTime
$RULE_DESCRIPTION = "DDC2 Generated Firewall Rule - $Dtime"
$RULE_NAME_PREFIX = "VNC Port - $Port --"
$Octet = '(?:0?0?[0-9]|0?[1-9][0-9]|1[0-9]{2}|2[0-5][0-5]|2[0-4][0-9])'
[regex] $IPv4Regex = "^(?:$Octet\.){3}$Octet$"
$checkIP = $IP -match $IPv4Regex
if($CheckIP) {
#check if the rules currently exist
$currentRules = (get-NetFirewallRule -Name "$RULE_NAME_PREFIX *" | Measure-Object).count
if($currentRules -gt 0) {
get-NetFirewallRule -Name "$RULE_NAME_PREFIX *" | remove-NetFirewallRule
write-log -LogData "Old Firewall Rules Found, removing..." -Silent
Start-sleep 1
}
$shh = New-NetFirewallRule -Name "$RULE_NAME_PREFIX TCP" -DisplayName "$RULE_NAME_PREFIX TCP" -Description $RULE_DESCRIPTION -Direction Inbound -LocalPort $Port -Protocol TCP -RemoteAddress $IP -Action Allow -Program $VNC_Path -Group 'Remote Desktop'
$shh = New-NetFirewallRule -Name "$RULE_NAME_PREFIX UDP" -DisplayName "$RULE_NAME_PREFIX UDP" -Description $RULE_DESCRIPTION -Direction Inbound -LocalPort $Port -Protocol UDP -RemoteAddress $IP -Action Allow -Program $VNC_Path -Group 'Remote Desktop'
} else {
write-log -LogData "ERROR: IP provided is invalid!" -Silent
}
write-log -LogData "Setup-Firewall-VNCPort Finished" -Silent
}
if($LoadTools) {Out-Report -Label "Setup-Firewall-VNCPort :" -Data 1 -Bool}
####################################################################################################
Function Set-Window {
<#
.SYNOPSIS
Retrieve/Set the window size and coordinates of a process window.
.DESCRIPTION
Retrieve/Set the size (height,width) and coordinates (x,y)
of a process window.
.PARAMETER ProcessName
Name of the process to determine the window characteristics.
(All processes if omitted).
.PARAMETER Id
Id of the process to determine the window characteristics.
.PARAMETER X
Set the position of the window in pixels from the left.
.PARAMETER Y
Set the position of the window in pixels from the top.
.PARAMETER Width
Set the width of the window.
.PARAMETER Height
Set the height of the window.
.PARAMETER Passthru
Returns the output object of the window.
.NOTES
Name: Set-Window
Author: Boe Prox
Version History:
1.0//Boe Prox - 11/24/2015 - Initial build
1.1//JosefZ - 19.05.2018 - Treats more process instances
of supplied process name properly
1.2//JosefZ - 21.02.2019 - Parameter Id
.OUTPUTS
None
System.Management.Automation.PSCustomObject
System.Object
.EXAMPLE
Get-Process powershell | Set-Window -X 20 -Y 40 -Passthru -Verbose
VERBOSE: powershell (Id=11140, Handle=132410)
Id : 11140
ProcessName : powershell
Size : 1134,781
TopLeft : 20,40
BottomRight : 1154,821
Description: Set the coordinates on the window for the process PowerShell.exe
.EXAMPLE
$windowArray = Set-Window -Passthru
WARNING: cmd (1096) is minimized! Coordinates will not be accurate.
PS C:\>$windowArray | Format-Table -AutoSize
Id ProcessName Size TopLeft BottomRight
-- ----------- ---- ------- -----------
1096 cmd 199,34 -32000,-32000 -31801,-31966
4088 explorer 1280,50 0,974 1280,1024
6880 powershell 1280,974 0,0 1280,974
Description: Get the coordinates of all visible windows and save them into the
$windowArray variable. Then, display them in a table view.
.EXAMPLE
Set-Window -Id $PID -Passthru | Format-Table
Id ProcessName Size TopLeft BottomRight
-- ----------- ---- ------- -----------
7840 pwsh 1024,638 0,0 1024,638
Description: Display the coordinates of the window for the current
PowerShell session in a table view.
#>
[cmdletbinding(DefaultParameterSetName='Name')]
Param (
[parameter(Mandatory=$False,
ValueFromPipelineByPropertyName=$True, ParameterSetName='Name')]
[string]$ProcessName='*',
[parameter(Mandatory=$True,
ValueFromPipeline=$False, ParameterSetName='Id')]
[int]$Id,
[int]$X,
[int]$Y,
[int]$Width,
[int]$Height,
[switch]$Passthru
)
Begin {
Try {
[void][Window]
} Catch {
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Window {
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetWindowRect(
IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public extern static bool MoveWindow(
IntPtr handle, int x, int y, int width, int height, bool redraw);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ShowWindow(
IntPtr handle, int state);
}
public struct RECT
{
public int Left; // x position of upper-left corner
public int Top; // y position of upper-left corner
public int Right; // x position of lower-right corner
public int Bottom; // y position of lower-right corner
}
"@
}
}
Process {
$Rectangle = New-Object RECT
If ( $PSBoundParameters.ContainsKey('Id') ) {
$Processes = Get-Process -Id $Id -ErrorAction SilentlyContinue
} else {
$Processes = Get-Process -Name "$ProcessName" -ErrorAction SilentlyContinue
}
if ( $null -eq $Processes ) {
If ( $PSBoundParameters['Passthru'] ) {
Write-Warning 'No process match criteria specified'
}
} else {
$Processes | ForEach-Object {
$Handle = $_.MainWindowHandle
Write-Verbose "$($_.ProcessName) `(Id=$($_.Id), Handle=$Handle`)"
if ( $Handle -eq [System.IntPtr]::Zero ) { return }
$Return = [Window]::GetWindowRect($Handle,[ref]$Rectangle)
If (-NOT $PSBoundParameters.ContainsKey('X')) {
$X = $Rectangle.Left
}
If (-NOT $PSBoundParameters.ContainsKey('Y')) {
$Y = $Rectangle.Top
}
If (-NOT $PSBoundParameters.ContainsKey('Width')) {
$Width = $Rectangle.Right - $Rectangle.Left
}
If (-NOT $PSBoundParameters.ContainsKey('Height')) {
$Height = $Rectangle.Bottom - $Rectangle.Top
}
If ( $Return ) {
$Return = [Window]::MoveWindow($Handle, $x, $y, $Width, $Height,$True)
}
If ( $PSBoundParameters['Passthru'] ) {
$Rectangle = New-Object RECT
$Return = [Window]::GetWindowRect($Handle,[ref]$Rectangle)
If ( $Return ) {
$Height = $Rectangle.Bottom - $Rectangle.Top
$Width = $Rectangle.Right - $Rectangle.Left
$Size = New-Object System.Management.Automation.Host.Size -ArgumentList $Width, $Height
$TopLeft = New-Object System.Management.Automation.Host.Coordinates -ArgumentList $Rectangle.Left , $Rectangle.Top
$BottomRight = New-Object System.Management.Automation.Host.Coordinates -ArgumentList $Rectangle.Right, $Rectangle.Bottom
If ($Rectangle.Top -lt 0 -AND
$Rectangle.Bottom -lt 0 -AND
$Rectangle.Left -lt 0 -AND
$Rectangle.Right -lt 0) {
Write-Warning "$($_.ProcessName) `($($_.Id)`) is minimized! Coordinates will not be accurate."
}
$Object = [PSCustomObject]@{
Id = $_.Id
ProcessName = $_.ProcessName
Size = $Size
TopLeft = $TopLeft
BottomRight = $BottomRight
}
$Object
}
}
}
}
}
}
if($LoadTools) {Out-Report -Label "Set-Window :" -Data 1 -Bool}
####################################################################################################
Function Tail-DDC2 {
<#
.DESCRIPTION
This Function will tail the DDC2 log file.
.EXAMPLE
Tail-DDC2
Tail-DDC2 -Tail 500
#>
Param (
[int]$Tail = 10
)
Get-Content $DDC2_LogFile -tail $Tail -wait
}
if($LoadTools) {Out-Report -Label "Tail-DDC2 :" -Data 1 -Bool}
####################################################################################################
Function Tail-Hooks {
<#
.DESCRIPTION
This Function will tail the DDC2 Hooks log file.
.EXAMPLE
Tail-Hooks
Tail-Hooks -Tail 500
#>
Param (
[int]$Tail = 10
)
Get-Content $DDC2_Hooks_Log -tail $Tail -wait
}
if($LoadTools) {Out-Report -Label "Tail-Hooks :" -Data 1 -Bool}
####################################################################################################
Function Tail-DCS {
<#
.DESCRIPTION
This Function will tail the DCS log file.
.EXAMPLE
Tail-DCS
Tail-DCS -Tail 500
#>
Param (
[int]$Tail = 10
)
Get-Content $DCS_Log -tail $Tail -wait
}
if($LoadTools) {Out-Report -Label "Tail-DCS :" -Data 1 -Bool}
####################################################################################################
Function Tail-SRS {
<#
.DESCRIPTION
This Function will tail the SRS log file.
.EXAMPLE
Tail-SRS
Tail-SRS -Tail 500
#>
Param (
[int]$Tail = 10
)
Get-Content $SRS_Log -tail $Tail -wait
}
if($LoadTools) {Out-Report -Label "Tail-SRS :" -Data 1 -Bool}
####################################################################################################
Function StringOutPorts {
<#
.DESCRIPTION
This Function will output a set of ports for a specific Process ID.
.EXAMPLE
Executing this: Tail-SRS
#>
Param ($Id)
$Netprocess = get-nettcpconnection -OwningProcess $Id -ErrorAction SilentlyContinue | Where-Object{$_.State -eq 'Listen'} | Select-Object localPort,State | Sort-Object LocalPort
$PortOut = ""
Foreach($item in $Netprocess) {
$PortOut = $PortOut + $item.LocalPort
if($item -ne $Netprocess[-1]) {$PortOut = $PortOut + ", "}
}
return $PortOut
}
if($LoadTools) {Out-Report -Label "StringOutPorts :" -Data 1 -Bool}
####################################################################################################
Function Set-Priority {
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)][string]$ProcessID,
[ValidateSet("Idle", "BelowNormal", "Normal", "AboveNormal", "HighPriority", "RealTime")]
[Parameter(Mandatory=$true)][string]$Priority
)
switch ($Priority){
"Idle" {[uint32]$priorityin = 64; break}
"BelowNormal" {[uint32]$priorityin = 16384; break}
"Normal" {[uint32]$priorityin = 32; break}
"AboveNormal" {[uint32]$priorityin = 32768; break}
"HighPriority" {[uint32]$priorityin = 128; break}
"RealTime" {[uint32]$priorityin = 256; break}
}