Marvel’s Strike Force – Team Builder

Sparked by a post on Reddit shortly after posting my MSFCalc for raid lane assignment, I’ve built a PowerShell based Team Builder for Marvel’s Strike Force.

The team builder will let you assign 5 heroes, based on each ‘stat’ category, will NOT let you use a hero in more than one category, shows you how many ‘positives’ there are for each hero selected, how many for each ‘stat’, and gives you the total count for the team. You are also able to save / export teams and import previously saved teams.

As noted by a user, depending on the restrictions for running scripts on your computer, you may need to run PowerShell as Admin to run the command ‘Set-ExecutionPolicy -ExecutionPolicy Bypass’ to enable scripts to run (instead of Bypass, you may need to use Unrestricted). This script itself does not need Admin rights.

MSFteambuilder 1.4

Note: As this is PowerShell, you’re free to modify and distribute as you wish, but please do give proper credit to me for this original work.

Changelog

  • V1.4 – Added Tier list rankings from Khasino. Selecting the Battletype will display the tier info for the heroes as 1=Trash, 2=Medicore, 3=Usable, 4=Demigod, 5=God
  • V1.3 – Updated with 1.4.1 Blitz infographic data from Khasino
  • V1.2 – Fixed stat calculations for columns and rows
  • V1.1 – Added stat calculations? I forget 🙂
  • V1.0 – Initial Release
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
# MSFTeamBuilder - Marvel's Strike Force Sure To Win Team Builder
#
# Created by Archimedez @ FrontRunnerTek.com
#
# Created:  2018-08-10
# Modified: 2018-08-14
# Version: 1.4
# Updated for 1.4.1 Blitz Infographic and Tier list from Khasino
# ======================================================================
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$POSHGUI_MyForm = New-Object System.Windows.Forms.Form
$POSHGUI_MyForm.Text="MSFTeamBuilder"
Try{$POSHGUI_MyForm.Icon="C:\MyIcon\MyIcon.ico"}Catch{}
$POSHGUI_MyForm.StartPosition = "CenterScreen"
$POSHGUI_MyForm.Size = New-Object System.Drawing.Size(820,350)
$POSHGUI_cmb_Hero1 = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_Hero1.Top="30"
$POSHGUI_cmb_Hero1.Left="10"
$POSHGUI_cmb_Hero1.Anchor="Left,Top"
$POSHGUI_cmb_Hero1.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_Hero1)
$POSHGUI_cmb_Hero1.Text=""
$POSHGUI_cmb_Hero1.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_cmb_Hero2 = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_Hero2.Top="30"
$POSHGUI_cmb_Hero2.Left="140"
$POSHGUI_cmb_Hero2.Anchor="Left,Top"
$POSHGUI_cmb_Hero2.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_Hero2)
$POSHGUI_cmb_Hero2.Text=""
$POSHGUI_cmb_Hero2.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_cmb_Hero3 = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_Hero3.Top="30"
$POSHGUI_cmb_Hero3.Left="270"
$POSHGUI_cmb_Hero3.Anchor="Left,Top"
$POSHGUI_cmb_Hero3.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_Hero3)
$POSHGUI_cmb_Hero3.Text=""
$POSHGUI_cmb_Hero3.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_cmb_Hero4 = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_Hero4.Top="30"
$POSHGUI_cmb_Hero4.Left="400"
$POSHGUI_cmb_Hero4.Anchor="Left,Top"
$POSHGUI_cmb_Hero4.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_Hero4)
$POSHGUI_cmb_Hero4.Text=""
$POSHGUI_cmb_Hero4.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_cmb_Hero5 = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_Hero5.Top="30"
$POSHGUI_cmb_Hero5.Left="540"
$POSHGUI_cmb_Hero5.Anchor="Left,Top"
$POSHGUI_cmb_Hero5.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_Hero5)
$POSHGUI_cmb_Hero5.Text=""
$POSHGUI_cmb_Hero5.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_cmb_Battletype = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_Battletype.Top="30"
$POSHGUI_cmb_Battletype.Left="680"
$POSHGUI_cmb_Battletype.Anchor="Left,Top"
$POSHGUI_cmb_Battletype.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_Battletype)
$POSHGUI_cmb_Battletype.Text=""
$POSHGUI_cmb_Battletype.Size = New-Object System.Drawing.Size(110,23)
$POSHGUI_Label6 = New-Object System.Windows.Forms.Label
$POSHGUI_Label6.Top="15"
$POSHGUI_Label6.Left="680"
$POSHGUI_Label6.Anchor="Left,Top"
$POSHGUI_Label6.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_Label6)
$POSHGUI_Label6.Text="Battle Type"
$POSHGUI_Label6.Size = New-Object System.Drawing.Size(120,23)
$POSHGUI_Label1 = New-Object System.Windows.Forms.Label
$POSHGUI_Label1.Top="15"
$POSHGUI_Label1.Left="540"
$POSHGUI_Label1.Anchor="Left,Top"
$POSHGUI_Label1.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_Label1)
$POSHGUI_Label1.Text="Damage with Utility"
$POSHGUI_Label1.Size = New-Object System.Drawing.Size(120,23)
$POSHGUI_Label2 = New-Object System.Windows.Forms.Label
$POSHGUI_Label2.Top="15"
$POSHGUI_Label2.Left="400"
$POSHGUI_Label2.Anchor="Left,Top"
$POSHGUI_Label2.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_Label2)
$POSHGUI_Label2.Text="Massive AOE Damage"
$POSHGUI_Label2.Size = New-Object System.Drawing.Size(120,23)
$POSHGUI_Label3 = New-Object System.Windows.Forms.Label
$POSHGUI_Label3.Top="15"
$POSHGUI_Label3.Left="270"
$POSHGUI_Label3.Anchor="Left,Top"
$POSHGUI_Label3.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_Label3)
$POSHGUI_Label3.Text="Enemy Buff Purge"
$POSHGUI_Label3.Size = New-Object System.Drawing.Size(120,23)
$POSHGUI_Label4 = New-Object System.Windows.Forms.Label
$POSHGUI_Label4.Top="15"
$POSHGUI_Label4.Left="140"
$POSHGUI_Label4.Anchor="Left,Top"
$POSHGUI_Label4.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_Label4)
$POSHGUI_Label4.Text="Early Burst Damage"
$POSHGUI_Label4.Size = New-Object System.Drawing.Size(120,23)
$POSHGUI_Label5 = New-Object System.Windows.Forms.Label
$POSHGUI_Label5.Top="15"
$POSHGUI_Label5.Left="8"
$POSHGUI_Label5.Anchor="Left,Top"
$POSHGUI_Label5.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_Label5)
$POSHGUI_Label5.Text="Team Wide Defense"
$POSHGUI_Label5.Size = New-Object System.Drawing.Size(120,23)
$POSHGUI_lbl_SureToWin = New-Object System.Windows.Forms.Label
$POSHGUI_lbl_SureToWin.Top="58"
$POSHGUI_lbl_SureToWin.Left="540"
$POSHGUI_lbl_SureToWin.Anchor="Left,Top"
$POSHGUI_lbl_SureToWin.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_lbl_SureToWin)
$POSHGUI_lbl_SureToWin.Text=""
$POSHGUI_lbl_SureToWin.Size = New-Object System.Drawing.Size(200,22)
$POSHGUI_DGV_TeamResults = New-Object System.Windows.Forms.DataGridView
$POSHGUI_DGV_TeamResults.Top="80"
$POSHGUI_DGV_TeamResults.Left="12"
$POSHGUI_DGV_TeamResults.Anchor="Left,Top"
$POSHGUI_DGV_TeamResults.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_DGV_TeamResults)
$POSHGUI_DGV_TeamResults.Text="DataGridView1"
$POSHGUI_DGV_TeamResults.Size = New-Object System.Drawing.Size(780,200)
$POSHGUI_btn_reset = New-Object System.Windows.Forms.Button
$POSHGUI_btn_reset.Top="55"
$POSHGUI_btn_reset.Left="10"
$POSHGUI_btn_reset.Anchor="Left,Top"
$POSHGUI_btn_reset.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_btn_reset)
$POSHGUI_btn_reset.Text="Reset"
$POSHGUI_btn_reset.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_btn_export = New-Object System.Windows.Forms.Button
$POSHGUI_btn_export.Top="55"
$POSHGUI_btn_export.Left="150"
$POSHGUI_btn_export.Anchor="Left,Top"
$POSHGUI_btn_export.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_btn_export)
$POSHGUI_btn_export.Text="Export Team"
$POSHGUI_btn_export.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_btn_import = New-Object System.Windows.Forms.Button
$POSHGUI_btn_import.Top="55"
$POSHGUI_btn_import.Left="300"
$POSHGUI_btn_import.Anchor="Left,Top"
$POSHGUI_btn_import.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_btn_import)
$POSHGUI_btn_import.Text="Import Team"
$POSHGUI_btn_import.Size = New-Object System.Drawing.Size(100,23)
# Add Custom Code Below - Do NOT Edit This Line!
# Rank: 5=GOD, 4=Demigod, 3=Useable, 2=Mediocre, 1=Trash
$csvData = @"
Hero,Team Wide Defense Buff,Enemy Buff Purge,Massive AOE Damage,Damage with Utility,Early Burst Damage,Campaign-RaidRank,ArenaOffense-Blitz,ArenaDefense-AI
Vision,No,Yes,Yes,Yes,No,5,5,4
Yondu,No,Yes,Yes,Yes,No,5,5,5
Black Widow,No,Yes,No,Yes,No,5,5,5
Doctor Strange,No,Yes,No,Yes,No,4,5,4
Hawkeye,No,Yes,No,Yes,No,4,4,4
Quake,No,Yes,Yes,No,No,5,5,5
Antman,No,Yes,No,No,No,3,4,3
Elektra,No,Yes,No,No,No,3,3,3
Hand Archer,No,Yes,No,No,No,3,3,2
Jessica Jones,No,Yes,No,No,No,4,4,4
Shield Operative,No,Yes,No,No,No,3,3,3
Captain America,Yes,Yes,No,No,No,4,4,4
Thanos,No,No,Yes,Yes,Yes,5,4,4
Wasp,No,No,Yes,Yes,Yes,4,4,3
Iron Man,No,No,Yes,No,Yes,5,4,4
Korath,No,No,No,Yes,Yes,4,5,4
Rocket Racoon,No,No,Yes,No,Yes,4,4,4
Starlord,No,No,No,Yes,Yes,4,4,3
Black Panther,No,No,No,Yes,No,5,4,3
Bullseye,No,No,No,No,Yes,3,3,3
Cable,No,No,No,Yes,No,4,5,3
Crossbones,No,No,Yes,No,No,4,4,4
Daredevil,No,No,No,No,Yes,4,4,3
Deadpool,No,No,No,No,Yes,5,5,4
Gamora,No,No,No,No,Yes,4,4,3
Merc Lieutenant,No,No,No,Yes,No,4,4,3
Merc Sniper,No,No,No,No,Yes,3,3,2
Mordo,No,No,No,Yes,No,4,4,3
Nobu,No,No,No,Yes,No,3,4,3
Spiderman,No,No,No,Yes,No,5,5,4
Thor,No,No,Yes,No,No,3,3,3
Winter Soldier,No,No,No,No,Yes,4,4,4
Hand Sentry,Yes,No,No,No,No,4,4,4
Kingpin,Yes,No,No,No,No,5,5,5
Luke Cage,Yes,No,No,No,No,4,3,3
Merc Riot Guard,Yes,No,No,No,No,4,4,4
Scarlet Witch,Yes,No,No,Yes,No,4,4,3
Loki,No,No,No,Yes,Yes,4,4,4
Okoye,No,No,No,Yes,Yes,4,4,3
Nick Fury,No,No,No,Yes,No,4,4,5
Ms Marvel,No,No,No,No,Yes,3,3,3
"
@

# Import Character Data
$charDataImport = $csvData | ConvertFrom-Csv

Function Load-ComboBoxes {

    # Clear comboboxes
    $POSHGUI_cmb_Hero1.Items.Clear() # Team-Wide Defense Buff
    $POSHGUI_cmb_Hero2.Items.Clear() # Early Burst Damage
    $POSHGUI_cmb_Hero3.Items.Clear() # Enemy Buff Purge
    $POSHGUI_cmb_Hero4.Items.Clear() # Massive AOE
    $POSHGUI_cmb_Hero5.Items.Clear() # Damage with Utility
    $POSHGUI_cmb_Battletype.Items.Clear()

    $POSHGUI_cmb_Hero1.Text = ""
    $POSHGUI_cmb_Hero2.Text = ""
    $POSHGUI_cmb_Hero3.Text = ""
    $POSHGUI_cmb_Hero4.Text = ""
    $POSHGUI_cmb_Hero5.Text = ""
    $POSHGUI_cmb_Battletype.Text = ""

    $POSHGUI_lbl_SureToWin.Text = ""

    [void]$POSHGUI_cmb_Battletype.Items.Add("Arena Defense / AI")
    [void]$POSHGUI_cmb_Battletype.Items.Add("Arena Offense / Blitz")
    [void]$POSHGUI_cmb_Battletype.Items.Add("Raid / Campaign")

    # Add characters to comboboxes
    ForEach ($char in $charDataImport){
       
        If ($char.'Team Wide Defense Buff' -eq 'Yes' -or $char.'Team Wide Defense Buff' -eq 'Meh'){
            [void]$POSHGUI_cmb_Hero1.items.Add($char.Hero)
        }

        If ($char.'Early Burst Damage' -eq 'Yes'){
            [void]$POSHGUI_cmb_Hero2.items.Add($char.Hero)
        }

        If ($char.'Enemy Buff Purge' -eq 'Yes'){
            [void]$POSHGUI_cmb_Hero3.items.Add($char.Hero)
        }

        If ($char.'Massive AOE Damage' -eq 'Yes'){
            [void]$POSHGUI_cmb_Hero4.items.Add($char.Hero)
        }

        If ($char.'Damage with Utility' -eq 'Yes'){
            [void]$POSHGUI_cmb_Hero5.items.Add($char.Hero)
        }

    }

}

Load-comboboxes

# Create Datatable for team building output
$Global:DToutput = New-Object System.Data.DataTable
[void]$Global:DToutput.Columns.Add("STAT")
[void]$Global:DToutput.Columns.Add("Hero 1")
[void]$Global:DToutput.Columns.Add("Hero 2")
[void]$Global:DToutput.Columns.Add("Hero 3")
[void]$Global:DToutput.Columns.Add("Hero 4")
[void]$Global:DToutput.Columns.Add("Hero 5")
[void]$Global:DToutput.Columns.Add("Sure To Win?")
$POSHGUI_DGV_TeamResults.DataSource = $Global:DToutput
$POSHGUI_DGV_TeamResults.AutoSizeColumnsMode = "AllCells"
$POSHGUI_DGV_TeamResults.ReadOnly = $true
$POSHGUI_DGV_TeamResults.AllowUserToAddRows = $false

Function Show-TeamOutput {

    # $POSHGUI_cmb_Hero1.SelectedItem = "Kingpin"

    $Hero1output = $charDataImport | Where-Object {$_.Hero -eq $POSHGUI_cmb_Hero1.SelectedItem}
    $Hero2output = $charDataImport | Where-Object {$_.Hero -eq $POSHGUI_cmb_Hero2.SelectedItem}
    $Hero3output = $charDataImport | Where-Object {$_.Hero -eq $POSHGUI_cmb_Hero3.SelectedItem}
    $Hero4output = $charDataImport | Where-Object {$_.Hero -eq $POSHGUI_cmb_Hero4.SelectedItem}
    $Hero5output = $charDataImport | Where-Object {$_.Hero -eq $POSHGUI_cmb_Hero5.SelectedItem}

    $DTteam = $Global:DToutput.Clone()    
    $row1 = $DTteam.NewRow()        
    $row1.STAT = "Team Wide Defense Buff"
    $row1.'Hero 1' = $Hero1output.'Team Wide Defense Buff'
    $row1.'Hero 2' = $Hero2output.'Team Wide Defense Buff'
    $row1.'Hero 3' = $Hero3output.'Team Wide Defense Buff'
    $row1.'Hero 4' = $Hero4output.'Team Wide Defense Buff'
    $row1.'Hero 5' = $Hero5output.'Team Wide Defense Buff'
    $row1Count = 0
    If ($Hero1output.'Team Wide Defense Buff' -eq 'Yes'){$row1Count += 1} ElseIf ($Hero1output.'Team Wide Defense Buff' -eq 'Meh'){$row1Count += 0.5}
    If ($Hero2output.'Team Wide Defense Buff' -eq 'Yes'){$row1Count += 1} ElseIf ($Hero2output.'Team Wide Defense Buff' -eq 'Meh'){$row1Count += 0.5}
    If ($Hero3output.'Team Wide Defense Buff' -eq 'Yes'){$row1Count += 1} ElseIf ($Hero3output.'Team Wide Defense Buff' -eq 'Meh'){$row1Count += 0.5}
    If ($Hero4output.'Team Wide Defense Buff' -eq 'Yes'){$row1Count += 1} ElseIf ($Hero4output.'Team Wide Defense Buff' -eq 'Meh'){$row1Count += 0.5}
    If ($Hero5output.'Team Wide Defense Buff' -eq 'Yes'){$row1Count += 1} ElseIf ($Hero5output.'Team Wide Defense Buff' -eq 'Meh'){$row1Count += 0.5}
    $row1.'Sure To Win?' =  $row1Count
    $DTteam.rows.Add($row1)

    $row2 = $DTteam.NewRow()        
    $row2.STAT = "Enemy Buff Purge"
    $row2.'Hero 1' = $Hero1output.'Enemy Buff Purge'
    $row2.'Hero 2' = $Hero2output.'Enemy Buff Purge'
    $row2.'Hero 3' = $Hero3output.'Enemy Buff Purge'
    $row2.'Hero 4' = $Hero4output.'Enemy Buff Purge'
    $row2.'Hero 5' = $Hero5output.'Enemy Buff Purge'
    $row2Count = 0
    If ($Hero1output.'Enemy Buff Purge' -eq 'Yes'){$row2Count += 1}
    If ($Hero2output.'Enemy Buff Purge' -eq 'Yes'){$row2Count += 1}
    If ($Hero3output.'Enemy Buff Purge' -eq 'Yes'){$row2Count += 1}
    If ($Hero4output.'Enemy Buff Purge' -eq 'Yes'){$row2Count += 1}
    If ($Hero5output.'Enemy Buff Purge' -eq 'Yes'){$row2Count += 1}
    $row2.'Sure To Win?' = $row2Count
    $DTteam.rows.Add($row2)

    $row3 = $DTteam.NewRow()        
    $row3.STAT = "Massive AOE Damage"
    $row3.'Hero 1' = $Hero1output.'Massive AOE Damage'
    $row3.'Hero 2' = $Hero2output.'Massive AOE Damage'
    $row3.'Hero 3' = $Hero3output.'Massive AOE Damage'
    $row3.'Hero 4' = $Hero4output.'Massive AOE Damage'
    $row3.'Hero 5' = $Hero5output.'Massive AOE Damage'
    $row3Count = 0
    If ($Hero1output.'Massive AOE Damage' -eq 'Yes'){$row3Count += 1}
    If ($Hero2output.'Massive AOE Damage' -eq 'Yes'){$row3Count += 1}
    If ($Hero3output.'Massive AOE Damage' -eq 'Yes'){$row3Count += 1}
    If ($Hero4output.'Massive AOE Damage' -eq 'Yes'){$row3Count += 1}
    If ($Hero5output.'Massive AOE Damage' -eq 'Yes'){$row3Count += 1}
    $row3.'Sure To Win?' = $row3Count
    $DTteam.rows.Add($row3)

    $row4 = $DTteam.NewRow()        
    $row4.STAT = "Damage with Utility"
    $row4.'Hero 1' = $Hero1output.'Damage with Utility'
    $row4.'Hero 2' = $Hero2output.'Damage with Utility'
    $row4.'Hero 3' = $Hero3output.'Damage with Utility'
    $row4.'Hero 4' = $Hero4output.'Damage with Utility'
    $row4.'Hero 5' = $Hero5output.'Damage with Utility'
    $row4Count = 0
    If ($Hero1output.'Damage with Utility' -eq 'Yes'){$row4Count += 1}
    If ($Hero2output.'Damage with Utility' -eq 'Yes'){$row4Count += 1}
    If ($Hero3output.'Damage with Utility' -eq 'Yes'){$row4Count += 1}
    If ($Hero4output.'Damage with Utility' -eq 'Yes'){$row4Count += 1}
    If ($Hero5output.'Damage with Utility' -eq 'Yes'){$row4Count += 1}
    $row4.'Sure To Win?' = $row4Count
    $DTteam.rows.Add($row4)

    $row5 = $DTteam.NewRow()        
    $row5.STAT = "Early Burst Damage"
    $row5.'Hero 1' = $Hero1output.'Early Burst Damage'
    $row5.'Hero 2' = $Hero2output.'Early Burst Damage'
    $row5.'Hero 3' = $Hero3output.'Early Burst Damage'
    $row5.'Hero 4' = $Hero4output.'Early Burst Damage'
    $row5.'Hero 5' = $Hero5output.'Early Burst Damage'
    $row5Count = 0
    If ($Hero1output.'Early Burst Damage' -eq 'Yes'){$row5Count += 1}
    If ($Hero2output.'Early Burst Damage' -eq 'Yes'){$row5Count += 1}
    If ($Hero3output.'Early Burst Damage' -eq 'Yes'){$row5Count += 1}
    If ($Hero4output.'Early Burst Damage' -eq 'Yes'){$row5Count += 1}
    If ($Hero5output.'Early Burst Damage' -eq 'Yes'){$row5Count += 1}
    $row5.'Sure To Win?' = $row5Count
    $DTteam.rows.Add($row5)

    $row6 = $DTteam.NewRow()        
    $row6.STAT = "Total Positives"

    $Hero1Count = 0
    $DTteam.Where{$_.'Hero 1' -eq 'Yes' }.ForEach({$Hero1Count += 1})
    $DTteam.Where{$_.'Hero 1' -eq 'Meh' }.ForEach({$Hero1Count += 0.5})
    $row6.'Hero 1' = $Hero1Count

    $Hero2Count = 0
    $DTteam.Where{$_.'Hero 2' -eq 'Yes' }.ForEach({$Hero2Count += 1})    
    $row6.'Hero 2' = $Hero2Count

    $Hero3Count = 0
    $DTteam.Where{$_.'Hero 3' -eq 'Yes' }.ForEach({$Hero3Count += 1})    
    $row6.'Hero 3' = $Hero3Count

    $Hero4Count = 0
    $DTteam.Where{$_.'Hero 4' -eq 'Yes' }.ForEach({$Hero4Count += 1})    
    $row6.'Hero 4' = $Hero4Count

    $Hero5Count = 0
    $DTteam.Where{$_.'Hero 5' -eq 'Yes' }.ForEach({$Hero5Count += 1})    
    $row6.'Hero 5' = $Hero5Count

    $totalCountPositives = [int]$row6.'Hero 1' + [int]$row6.'Hero 2' + [int]$row6.'Hero 3' + [int]$row6.'Hero 4' + [int]$row6.'Hero 5'

    $row6.'Sure To Win?' = $totalCountPositives
    $DTteam.rows.Add($row6)

    $row7 = $DTteam.NewRow()        
    $row7.STAT = "Hero Tier: 1 (Trash) to 5 (God)"
    Switch ($POSHGUI_cmb_Battletype.SelectedItem){
        # Campaign-RaidRank,ArenaOffense-Blitz,ArenaDefense-AI
        "Arena Defense / AI" {        
            $row7.'Hero 1' = $Hero1output.'ArenaDefense-AI'
            $row7.'Hero 2' = $Hero2output.'ArenaDefense-AI'
            $row7.'Hero 3' = $Hero3output.'ArenaDefense-AI'
            $row7.'Hero 4' = $Hero4output.'ArenaDefense-AI'
            $row7.'Hero 5' = $Hero5output.'ArenaDefense-AI'
        }
        "Arena Offense / Blitz" {
            $row7.'Hero 1' = $Hero1output.'ArenaOffense-Blitz'
            $row7.'Hero 2' = $Hero2output.'ArenaOffense-Blitz'
            $row7.'Hero 3' = $Hero3output.'ArenaOffense-Blitz'
            $row7.'Hero 4' = $Hero4output.'ArenaOffense-Blitz'
            $row7.'Hero 5' = $Hero5output.'ArenaOffense-Blitz'        
        }
        "Raid / Campaign" {
            $row7.'Hero 1' = $Hero1output.'Campaign-RaidRank'
            $row7.'Hero 2' = $Hero2output.'Campaign-RaidRank'
            $row7.'Hero 3' = $Hero3output.'Campaign-RaidRank'
            $row7.'Hero 4' = $Hero4output.'Campaign-RaidRank'
            $row7.'Hero 5' = $Hero5output.'Campaign-RaidRank'            
        }

    }
   
    $DTteam.rows.Add($row7)

    $POSHGUI_DGV_TeamResults.DataSource = $DTteam
}


$POSHGUI_cmb_Hero1.Add_SelectedValueChanged({

    $POSHGUI_cmb_Hero2.Items.Remove($POSHGUI_cmb_Hero1.SelectedItem)
    $POSHGUI_cmb_Hero3.Items.Remove($POSHGUI_cmb_Hero1.SelectedItem)
    $POSHGUI_cmb_Hero4.Items.Remove($POSHGUI_cmb_Hero1.SelectedItem)
    $POSHGUI_cmb_Hero5.Items.Remove($POSHGUI_cmb_Hero1.SelectedItem)

    If ($POSHGUI_cmb_Hero1.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero2.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero3.SelectedIndex -ne -1 `
            -and $POSHGUI_cmb_Hero4.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero5.SelectedIndex -ne -1 -and $POSHGUI_cmb_Battletype.SelectedIndex -ne -1){
                $POSHGUI_lbl_SureToWin.Text = "Team Is Sure To Win!!! (Probably)"
                Show-TeamOutput
    }

})
$POSHGUI_cmb_Hero2.Add_SelectedValueChanged({

    $POSHGUI_cmb_Hero1.Items.Remove($POSHGUI_cmb_Hero2.SelectedItem)
    $POSHGUI_cmb_Hero3.Items.Remove($POSHGUI_cmb_Hero2.SelectedItem)
    $POSHGUI_cmb_Hero4.Items.Remove($POSHGUI_cmb_Hero2.SelectedItem)
    $POSHGUI_cmb_Hero5.Items.Remove($POSHGUI_cmb_Hero2.SelectedItem)

    If ($POSHGUI_cmb_Hero1.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero2.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero3.SelectedIndex -ne -1 `
            -and $POSHGUI_cmb_Hero4.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero5.SelectedIndex -ne -1 -and $POSHGUI_cmb_Battletype.SelectedIndex -ne -1){
                $POSHGUI_lbl_SureToWin.Text = "Team Is Sure To Win!!! (Probably)"
                Show-TeamOutput
    }

})
$POSHGUI_cmb_Hero3.Add_SelectedValueChanged({

    $POSHGUI_cmb_Hero1.Items.Remove($POSHGUI_cmb_Hero3.SelectedItem)
    $POSHGUI_cmb_Hero2.Items.Remove($POSHGUI_cmb_Hero3.SelectedItem)
    $POSHGUI_cmb_Hero4.Items.Remove($POSHGUI_cmb_Hero3.SelectedItem)
    $POSHGUI_cmb_Hero5.Items.Remove($POSHGUI_cmb_Hero3.SelectedItem)

    If ($POSHGUI_cmb_Hero1.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero2.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero3.SelectedIndex -ne -1 `
            -and $POSHGUI_cmb_Hero4.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero5.SelectedIndex -ne -1 -and $POSHGUI_cmb_Battletype.SelectedIndex -ne -1){
                $POSHGUI_lbl_SureToWin.Text = "Team Is Sure To Win!!! (Probably)"
                Show-TeamOutput
    }

})
$POSHGUI_cmb_Hero4.Add_SelectedValueChanged({

    $POSHGUI_cmb_Hero1.Items.Remove($POSHGUI_cmb_Hero4.SelectedItem)
    $POSHGUI_cmb_Hero2.Items.Remove($POSHGUI_cmb_Hero4.SelectedItem)
    $POSHGUI_cmb_Hero3.Items.Remove($POSHGUI_cmb_Hero4.SelectedItem)
    $POSHGUI_cmb_Hero5.Items.Remove($POSHGUI_cmb_Hero4.SelectedItem)

    If ($POSHGUI_cmb_Hero1.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero2.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero3.SelectedIndex -ne -1 `
            -and $POSHGUI_cmb_Hero4.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero5.SelectedIndex -ne -1 -and $POSHGUI_cmb_Battletype.SelectedIndex -ne -1){
                $POSHGUI_lbl_SureToWin.Text = "Team Is Sure To Win!!! (Probably)"
                Show-TeamOutput
    }

})
$POSHGUI_cmb_Hero5.Add_SelectedValueChanged({

    $POSHGUI_cmb_Hero1.Items.Remove($POSHGUI_cmb_Hero5.SelectedItem)
    $POSHGUI_cmb_Hero2.Items.Remove($POSHGUI_cmb_Hero5.SelectedItem)
    $POSHGUI_cmb_Hero3.Items.Remove($POSHGUI_cmb_Hero5.SelectedItem)
    $POSHGUI_cmb_Hero4.Items.Remove($POSHGUI_cmb_Hero5.SelectedItem)

    If ($POSHGUI_cmb_Hero1.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero2.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero3.SelectedIndex -ne -1 `
            -and $POSHGUI_cmb_Hero4.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero5.SelectedIndex -ne -1 -and $POSHGUI_cmb_Battletype.SelectedIndex -ne -1){
                $POSHGUI_lbl_SureToWin.Text = "Team Is Sure To Win!!! (Probably)"
                Show-TeamOutput
    }

})
$POSHGUI_cmb_Battletype.Add_SelectedValueChanged({

   
    If ($POSHGUI_cmb_Hero1.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero2.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero3.SelectedIndex -ne -1 `
            -and $POSHGUI_cmb_Hero4.SelectedIndex -ne -1 -and $POSHGUI_cmb_Hero5.SelectedIndex -ne -1 -and $POSHGUI_cmb_Battletype.SelectedIndex -ne -1){
                $POSHGUI_lbl_SureToWin.Text = "Team Is Sure To Win!!! (Probably)"
                Show-TeamOutput
    }

})


Function Reset-All {

    Load-ComboBoxes
    $POSHGUI_DGV_TeamResults.DataSource.Clear()

}

$POSHGUI_btn_reset.Add_Click({ Reset-All })

$POSHGUI_btn_export.Add_Click({ Export-Team })

$POSHGUI_btn_import.Add_Click({ Import-Team })

Function Export-Team {
   
    $teamExportFile = Get-FileNameExport -initialDirectory $DefaultPath

    If ($teamExportFile){
        $team = [PSCustomObject] @{
            Hero1 = $POSHGUI_cmb_Hero1.SelectedItem
            Hero2 = $POSHGUI_cmb_Hero2.SelectedItem
            Hero3 = $POSHGUI_cmb_Hero3.SelectedItem
            Hero4 = $POSHGUI_cmb_Hero4.SelectedItem
            Hero5 = $POSHGUI_cmb_Hero5.SelectedItem
        }
        $team | ConvertTo-Json | Out-File $teamExportFile
    }
}

Function Import-Team {
   
    $teamImportFile = Get-FileNameImport -initialDirectory $DefaultPath

    If ($teamImportFile){
        Reset-All

        $team = Get-Content $teamImportFile | ConvertFrom-Json

        $POSHGUI_cmb_Hero1.SelectedItem = $team.Hero1
        $POSHGUI_cmb_Hero2.SelectedItem = $team.Hero2
        $POSHGUI_cmb_Hero3.SelectedItem = $team.Hero3
        $POSHGUI_cmb_Hero4.SelectedItem = $team.Hero4
        $POSHGUI_cmb_Hero5.SelectedItem = $team.Hero5

    }

}

$DefaultPath = "$env:USERPROFILE\Documents"

Function Get-FileNameExport($initialDirectory)  {
    $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
    $SaveFileDialog.initialDirectory = $initialDirectory
    $SaveFileDialog.filter = “JSON files (*.json)|*.json”
    $SaveFileDialog.ShowDialog() | Out-Null
    $SaveFileDialog.filename          
}
 
Function Get-FileNameImport($initialDirectory)  {
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.initialDirectory = $initialDirectory
    $OpenFileDialog.filter = “JSON files (*.json)|*.json”
    $OpenFileDialog.ShowDialog() | Out-Null
    $OpenFileDialog.filename          
}

# Add Custom Code Above - Do NOT Edit This Line!
$null = $POSHGUI_MyForm.ShowDialog()

Marvel’s Strike Force – Raid / Lane Assignment Calculator

MSFCalc

This calculator for Marvel’s Strike Force mobile based game is for determining Raid Lane assignment for Alliance members.

There are options to assign by Strongest Team Power (STP), Total Collection Power(TCP), or Randomly.

You just plug in your player’s information, edit the lane difficulty for the desired raids (you can add and delete raids), then select your assignment scheme, and calculate the assignments. It’s just that easy!

If you have any questions, comments or suggestions, do leave them below.

The script does not require admin rights, nor does it perform any web calls.
Download below or copy/paste from the code below into a text file and save as MSFcalc.ps1.
Right-click the file and select Run With PowerShell.

The script will create two files on your desktop that contain the player data and the raid lane difficulty data. MSFPlayerData.json and MSFRaidData.json

As noted by a user, depending on the restrictions for running scripts on your computer, you may need to run PowerShell as Admin to run the command ‘Set-ExecutionPolicy -ExecutionPolicy Bypass’ to enable scripts to run (instead of Bypass, you may need to use Unrestricted). This script itself does not need Admin rights.

Note: As this is PowerShell, you’re free to modify and distribute as you wish, but please do give proper credit to me for this original work.

MSFCalc Example
MSFCalc Example

Changelog

  • 1.3 – Added a lane format selection to change between Letters and Numbers. This is only applicable to the Raid Lane Assignment Output and not the Raid / Lane difficulty setup so as to maintain backwards compatibility for previous versions. A=1, B=2, C=3 etc.
  • 1.2 – Reduced code for redundant calculation operations
  • 1.1 – Changed lane assignments from 1 to 9, to A through I, which reflects the beginning of the node identifiers in game
  • 1.0 – Initial Release
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
# MSFCalc - Marvel's Strike Force Raid / Lane Assignment Calculator
#
# Created by Archimedez @ FrontRunnerTek.com
#
# Created:  2018-08-07
# Modified: 2018-08-16
# Version: 1.3
# ======================================================================
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$POSHGUI_MyForm = New-Object System.Windows.Forms.Form
$POSHGUI_MyForm.Text="MSFCalc"
$POSHGUI_MyForm.StartPosition = "CenterScreen"
$POSHGUI_MyForm.Size = New-Object System.Drawing.Size(900,620)
$POSHGUI_DGV_PlayerData = New-Object System.Windows.Forms.DataGridView
$POSHGUI_DGV_PlayerData.Top="45"
$POSHGUI_DGV_PlayerData.Left="10"
$POSHGUI_DGV_PlayerData.Anchor="Left,Top"
$POSHGUI_DGV_PlayerData.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_DGV_PlayerData)
$POSHGUI_DGV_PlayerData.Text="DataGridView1"
$POSHGUI_DGV_PlayerData.Size = New-Object System.Drawing.Size(425,400)
$POSHGUI_DGV_RaidOutput = New-Object System.Windows.Forms.DataGridView
$POSHGUI_DGV_RaidOutput.Top="45"
$POSHGUI_DGV_RaidOutput.Left="450"
$POSHGUI_DGV_RaidOutput.Anchor="Left,Top"
$POSHGUI_DGV_RaidOutput.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_DGV_RaidOutput)
$POSHGUI_DGV_RaidOutput.Text="DataGridView2"
$POSHGUI_DGV_RaidOutput.Size = New-Object System.Drawing.Size(425,400)
$POSHGUI_cmb_raidSelect = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_raidSelect.Top="19"
$POSHGUI_cmb_raidSelect.Left="540"
$POSHGUI_cmb_raidSelect.Anchor="Left,Top"
$POSHGUI_cmb_raidSelect.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_raidSelect)
$POSHGUI_cmb_raidSelect.Text="EDIT Raids & Lanes, or Choose A Raid To Assign"
$POSHGUI_cmb_raidSelect.Size = New-Object System.Drawing.Size(334,23)
$POSHGUI_lbl_raidSelect = New-Object System.Windows.Forms.Label
$POSHGUI_lbl_raidSelect.Top="25"
$POSHGUI_lbl_raidSelect.Left="450"
$POSHGUI_lbl_raidSelect.Anchor="Left,Top"
$POSHGUI_lbl_raidSelect.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_lbl_raidSelect)
$POSHGUI_lbl_raidSelect.Text="Select Raid"
$POSHGUI_lbl_raidSelect.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_btn_calcAssignment = New-Object System.Windows.Forms.Button
$POSHGUI_btn_calcAssignment.Top="451"
$POSHGUI_btn_calcAssignment.Left="675"
$POSHGUI_btn_calcAssignment.Anchor="Left,Top"
$POSHGUI_btn_calcAssignment.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_btn_calcAssignment)
$POSHGUI_btn_calcAssignment.Text="Calculate Assignments"
$POSHGUI_btn_calcAssignment.Size = New-Object System.Drawing.Size(200,23)
$POSHGUI_lbl_AllianceCountHeader = New-Object System.Windows.Forms.Label
$POSHGUI_lbl_AllianceCountHeader.Top="25"
$POSHGUI_lbl_AllianceCountHeader.Left="10"
$POSHGUI_lbl_AllianceCountHeader.Anchor="Left,Top"
$POSHGUI_lbl_AllianceCountHeader.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_lbl_AllianceCountHeader)
$POSHGUI_lbl_AllianceCountHeader.Text="Alliance Count"
$POSHGUI_lbl_AllianceCountHeader.Size = New-Object System.Drawing.Size(80,23)
$POSHGUI_lbl_AllianceCount = New-Object System.Windows.Forms.Label
$POSHGUI_lbl_AllianceCount.Top="25"
$POSHGUI_lbl_AllianceCount.Left="110"
$POSHGUI_lbl_AllianceCount.Anchor="Left,Top"
$POSHGUI_lbl_AllianceCount.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_lbl_AllianceCount)
$POSHGUI_lbl_AllianceCount.Text="0/24"
$POSHGUI_lbl_AllianceCount.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_DGV_laneDifficulty = New-Object System.Windows.Forms.DataGridView
$POSHGUI_DGV_laneDifficulty.Top="480"
$POSHGUI_DGV_laneDifficulty.Left="10"
$POSHGUI_DGV_laneDifficulty.Anchor="Left,Top,Bottom"
$POSHGUI_DGV_laneDifficulty.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_DGV_laneDifficulty)
$POSHGUI_DGV_laneDifficulty.Text="DataGridView3"
$POSHGUI_DGV_laneDifficulty.Size = New-Object System.Drawing.Size(865,90)
$POSHGUI_lbl_laneDifficulty = New-Object System.Windows.Forms.Label
$POSHGUI_lbl_laneDifficulty.Top="460"
$POSHGUI_lbl_laneDifficulty.Left="10"
$POSHGUI_lbl_laneDifficulty.Anchor="Left,Top"
$POSHGUI_lbl_laneDifficulty.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_lbl_laneDifficulty)
$POSHGUI_lbl_laneDifficulty.Text="Define Lane Difficulty (1 = Easiest, 9 = Hardest, 0 = Lane Unused)"
$POSHGUI_lbl_laneDifficulty.Size = New-Object System.Drawing.Size(350,23)
$POSHGUI_cmb_AssignType = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_AssignType.Top="453"
$POSHGUI_cmb_AssignType.Left="564"
$POSHGUI_cmb_AssignType.Anchor="Left,Top"
$POSHGUI_cmb_AssignType.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_AssignType)
$POSHGUI_cmb_AssignType.Text="Select Scheme"
$POSHGUI_cmb_AssignType.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_lbl_assignType = New-Object System.Windows.Forms.Label
$POSHGUI_lbl_assignType.Top="458"
$POSHGUI_lbl_assignType.Left="449"
$POSHGUI_lbl_assignType.Anchor="Left,Top"
$POSHGUI_lbl_assignType.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_lbl_assignType)
$POSHGUI_lbl_assignType.Text="Assignment Scheme"
$POSHGUI_lbl_assignType.Size = New-Object System.Drawing.Size(150,23)
$POSHGUI_cmb_laneFormat = New-Object System.Windows.Forms.ComboBox
$POSHGUI_cmb_laneFormat.Top="19"
$POSHGUI_cmb_laneFormat.Left="335"
$POSHGUI_cmb_laneFormat.Anchor="Left,Top"
$POSHGUI_cmb_laneFormat.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_cmb_laneFormat)
$POSHGUI_cmb_laneFormat.Text="Select"
$POSHGUI_cmb_laneFormat.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_lbl_laneFormat = New-Object System.Windows.Forms.Label
$POSHGUI_lbl_laneFormat.Top="25"
$POSHGUI_lbl_laneFormat.Left="255"
$POSHGUI_lbl_laneFormat.Anchor="Left,Top"
$POSHGUI_lbl_laneFormat.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_lbl_laneFormat)
$POSHGUI_lbl_laneFormat.Text="Lane Format"
$POSHGUI_lbl_laneFormat.Size = New-Object System.Drawing.Size(100,23)
# Add Custom Code Below - Do NOT Edit This Line!
CLS

# Relaunch in regular PowerShell console window if launched in ISE
If ($host.Name -like "*ISE*"){    
    Write-Warning "Launching into a regular powershell console window"
    If ($MyInvocation.MyCommand.Path) {
        $scriptpath = $MyInvocation.MyCommand.Path -replace ' ', '` '
        Invoke-Expression "start powershell {$scriptpath}"
    }
    break
}

$DefaultPath = "$env:USERPROFILE\Documents"
$savePlayerDataFile = "$env:USERPROFILE\Desktop\MSFPlayerData.json"
$saveRaidDataFile = "$env:USERPROFILE\Desktop\MSFRaidData.json"

[void]$POSHGUI_cmb_AssignType.Items.Add("STP")
[void]$POSHGUI_cmb_AssignType.Items.Add("TCP")
[void]$POSHGUI_cmb_AssignType.Items.Add("Random")

[void]$POSHGUI_cmb_laneFormat.Items.Add("Letters")
[void]$POSHGUI_cmb_laneFormat.Items.Add("Numbers")

$POSHGUI_cmb_laneFormat.Add_SelectedValueChanged({
    Lane-Assignment
})

Function Lane-Assignment {

    switch ($POSHGUI_cmb_laneFormat.SelectedItem)
    {
        'Letters' {
       
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane A' -or $_.Lane -eq 'Lane 1'}).LANE = 'Lane A'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane B' -or $_.Lane -eq 'Lane 2'}).LANE = 'Lane B'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane C' -or $_.Lane -eq 'Lane 3'}).LANE = 'Lane C'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane D' -or $_.Lane -eq 'Lane 4'}).LANE = 'Lane D'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane E' -or $_.Lane -eq 'Lane 5'}).LANE = 'Lane E'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane F' -or $_.Lane -eq 'Lane 6'}).LANE = 'Lane F'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane G' -or $_.Lane -eq 'Lane 7'}).LANE = 'Lane G'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane H' -or $_.Lane -eq 'Lane 8'}).LANE = 'Lane H'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane I' -or $_.Lane -eq 'Lane 9'}).LANE = 'Lane I'}Catch{}
       
        }
        'Numbers' {
       
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane A' -or $_.Lane -eq 'Lane 1'}).LANE = 'Lane 1'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane B' -or $_.Lane -eq 'Lane 2'}).LANE = 'Lane 2'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane C' -or $_.Lane -eq 'Lane 3'}).LANE = 'Lane 3'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane D' -or $_.Lane -eq 'Lane 4'}).LANE = 'Lane 4'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane E' -or $_.Lane -eq 'Lane 5'}).LANE = 'Lane 5'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane F' -or $_.Lane -eq 'Lane 6'}).LANE = 'Lane 6'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane G' -or $_.Lane -eq 'Lane 7'}).LANE = 'Lane 7'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane H' -or $_.Lane -eq 'Lane 8'}).LANE = 'Lane 8'}Catch{}
            Try{($POSHGUI_DGV_RaidOutput.DataSource.Rows | Where-Object {$_.Lane -eq 'Lane I' -or $_.Lane -eq 'Lane 9'}).LANE = 'Lane 9'}Catch{}

        }

    }

}

Function Save-Data {    
        # Export the player data          
        $POSHGUI_DGV_PlayerData.DataSource | Select-Object * -ExcludeProperty ItemArray, Table, RowError, RowState, HasErrors | ConvertTo-Json | Out-File $savePlayerDataFile
        # Ensure tables are saved and validated before saving so we don't write empty files
        # Export raid / lane data
    If ($POSHGUI_cmb_raidSelect.SelectedItem -eq "EDIT Raids & Lanes, or Choose A Raid To Assign") {        
        $POSHGUI_DGV_laneDifficulty.DataSource |  Select-Object * -ExcludeProperty ItemArray, Table, RowError, RowState, HasErrors | ConvertTo-Json | Out-File $saveRaidDataFile
        $POSHGUI_cmb_raidSelect.Items.Clear()
        $POSHGUI_cmb_raidSelect.Items.Add("EDIT Raids & Lanes, or Choose A Raid To Assign")
        ForEach ($raid in $Global:DTlaneDifficulty){
            If ($raid.raid -ne $null -and $POSHGUI_cmb_raidSelect.Items -notcontains $raid.Raid){            
                [void]$POSHGUI_cmb_raidSelect.Items.Add($raid.Raid)
            }
        }
    }
}

# Create systems list datatable
[System.Data.DataTable]$Global:DTplayers = New-Object System.Data.Datatable
$Global:DTplayers.TableName = "PlayerData"
[void]$Global:DTplayers.Columns.Add("PlayerName")
[void]$Global:DTplayers.Columns.Add("STP")
[void]$Global:DTplayers.Columns.Add("TCP")
$POSHGUI_DGV_PlayerData.Font = New-Object System.Drawing.Font("Lucida Console",10,[System.Drawing.FontStyle]::Regular)
$POSHGUI_DGV_PlayerData.DataSource = $Global:DTplayers
$POSHGUI_DGV_PlayerData.AutoSizeColumnsMode = "Fill"

# Create raid assignment datatable
[System.Data.DataTable]$Global:DTraidOutput = New-Object System.Data.Datatable
[void]$Global:DTraidOutput.Columns.Add("LANE")
[void]$Global:DTraidOutput.Columns.Add("TEAM 1")
[void]$Global:DTraidOutput.Columns.Add("TEAM 2")
[void]$Global:DTraidOutput.Columns.Add("TEAM 3")
$POSHGUI_DGV_RaidOutput.Font = New-Object System.Drawing.Font("Lucida Console",10,[System.Drawing.FontStyle]::Regular)
$POSHGUI_DGV_RaidOutput.DataSource = $Global:DTraidOutput
$POSHGUI_DGV_RaidOutput.AutoSizeColumnsMode = "AllCells"
$POSHGUI_DGV_RaidOutput.AllowUserToAddRows = $false
$POSHGUI_DGV_RaidOutput.RowHeadersVisible = $false
$POSHGUI_DGV_RaidOutput.Padding = "5,5,5,5"

# Create Raid / Lane difficult settings datatable
[System.Data.DataTable]$Global:DTlaneDifficulty = New-Object System.Data.DataTable
$Global:DTlaneDifficulty.TableName = "LaneData"
[void]$Global:DTlaneDifficulty.Columns.Add("Raid")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane A")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane B")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane C")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane D")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane E")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane F")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane G")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane H")
[void]$Global:DTlaneDifficulty.Columns.Add("Lane I")
$POSHGUI_DGV_laneDifficulty.Font = New-Object System.Drawing.Font("Lucida Console",8,[System.Drawing.FontStyle]::Regular)
$POSHGUI_DGV_laneDifficulty.AutoSizeColumnsMode = "Fill"

If ($Global:DTlaneDifficulty.Rows.Count -lt 1){
   $newRow = $Global:DTlaneDifficulty.NewRow()  
   [void]$Global:DTlaneDifficulty.Rows.Add($newRow)
}

Function Get-Assignments {
    Param
    (        
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        $Scheme
    )
   
    Write-Host "Calculating Assignments using $Scheme"
    $tempDT = $Global:DTraidOutput.Clone()
    $playerInfo = $POSHGUI_DGV_PlayerData.DataSource

    switch ($Scheme)
    {
        'STP' { $playerInfoFixed = $playerInfo | Sort-Object  @{e={$_.STP -as [int]}} -Descending }
        'TCP' { $playerInfoFixed = $playerInfo | Sort-Object @{e={$_.TCP -as [int]}} -Descending  }
        'Random' { $playerInfoFixed = $playerInfo | Sort-Object {Get-Random} }
        Default { Write-Host "Invalid Scheme Selected"}
    }
   
    $laneInfo = $POSHGUI_DGV_laneDifficulty.DataSource

    $lane1 = [pscustomobject]@{
    Lane = "Lane A"
    Difficulty = $([int]$laneInfo.item("Lane A"))
    }
    $lane2 = [pscustomobject]@{
    Lane = "Lane B"
    Difficulty = $([int]$laneInfo.item("Lane B"))
    }
    $lane3 = [pscustomobject]@{
    Lane = "Lane C"
    Difficulty = $([int]$laneInfo.item("Lane C"))
    }
    $lane4 = [pscustomobject]@{
    Lane = "Lane D"
    Difficulty = $([int]$laneInfo.item("Lane D"))
    }
    $lane5 = [pscustomobject]@{
    Lane = "Lane E"
    Difficulty = $([int]$laneInfo.item("Lane E"))
    }
    $lane6 = [pscustomobject]@{
    Lane = "Lane F"
    Difficulty = $([int]$laneInfo.item("Lane F"))
    }
    $lane7 = [pscustomobject]@{
    Lane = "Lane G"
    Difficulty = $([int]$laneInfo.item("Lane G"))
    }
    $lane8 = [pscustomobject]@{
    Lane = "Lane H"
    Difficulty = $([int]$laneInfo.item("Lane H"))
    }
    $lane9 = [pscustomobject]@{
    Lane = "Lane I"
    Difficulty = $([int]$laneInfo.item("Lane I"))
    }

        switch ($Scheme)
    {        
        'Random' { $laneArray = @($lane1,$lane2,$lane3,$lane4,$lane5,$lane6,$lane7,$lane8,$lane9) | Sort-Object {Get-Random} }
        Default { $laneArray = @($lane1,$lane2,$lane3,$lane4,$lane5,$lane6,$lane7,$lane8,$lane9) | Sort-Object Difficulty -Descending }
    }

    $pCnt = 0
    ForEach ($lane in $laneArray){
        If ($pCnt -lt 23){
            $newRow = $tempDT.NewRow()
            $newRow.LANE = $lane.Lane
            Try{$newrow.'TEAM 1' = $playerInfoFixed.playername.item($pCnt)}Catch{} ; $pCnt += 1
            Try{$newRow.'TEAM 2' = $playerInfoFixed.playername.item($pCnt)}Catch{} ; $pCnt += 1
            Try{$newRow.'TEAM 3' = $playerInfoFixed.playername.item($pCnt)}Catch{} ; $pCnt += 1
            $tempDT.Rows.Add($newRow)
        }
    }

    $POSHGUI_DGV_RaidOutput.DataSource = $tempDT    
    Lane-Assignment
}

$POSHGUI_btn_calcAssignment.Enabled = $false
$POSHGUI_btn_calcAssignment.Add_Click({

    If ($POSHGUI_cmb_raidSelect.SelectedItem -eq "EDIT Raids & Lanes, or Choose A Raid To Assign" -or $POSHGUI_cmb_raidSelect.SelectedIndex -eq -1){
        # Invalid Selection
    }Else{
        Get-Assignments -Scheme $POSHGUI_cmb_AssignType.SelectedItem
        $POSHGUI_DGV_RaidOutput.ClipboardCopyMode = [System.Windows.Forms.DataGridViewClipboardCopyMode]::EnableAlwaysIncludeHeaderText    
        Write-Host "Calculations Complete"
    }
})


Function Load-Data {
  If (Test-Path -Path $savePlayerDataFile -ErrorAction SilentlyContinue) {
   
    $playerInfo  = Get-Content $savePlayerDataFile -Raw | ConvertFrom-Json
    $raidInfo = Get-Content $saveRaidDataFile -Raw | ConvertFrom-Json

    $Global:DTplayers.Rows.Clear()
    ForEach ($player in $playerInfo){
        $newRow = $Global:DTplayers.NewRow()
        $newRow.PlayerName = $player.PlayerName
        $newrow.STP = $player.STP
        $newRow.TCP = $player.TCP
        [void]$Global:DTplayers.Rows.Add($newRow)
    }

    $Global:DTlaneDifficulty.rows.Clear()
    ForEach ($raid in $raidInfo){
        If ($raid.raid -ne $null){
            $newRow = $Global:DTlaneDifficulty.NewRow()
            $newRow.Raid = $raid.Raid
            $newrow.'Lane A' = $raid.'Lane A'
            $newrow.'Lane B' = $raid.'Lane B'
            $newrow.'Lane C' = $raid.'Lane C'
            $newrow.'Lane D' = $raid.'Lane D'
            $newrow.'Lane E' = $raid.'Lane E'
            $newrow.'Lane F' = $raid.'Lane F'
            $newrow.'Lane G' = $raid.'Lane G'
            $newrow.'Lane H' = $raid.'Lane H'
            $newrow.'Lane I' = $raid.'Lane I'
            [void]$Global:DTlaneDifficulty.Rows.Add($newRow)
            [void]$POSHGUI_cmb_raidSelect.Items.Add($raid.Raid)
        }
    }

  } Else {
    $POSHGUI_DGV_laneDifficulty.DataSource = $Global:DTlaneDifficulty
  }
}

[void]$POSHGUI_cmb_raidSelect.Items.Add("EDIT Raids & Lanes, or Choose A Raid To Assign")

$POSHGUI_cmb_raidSelect.Add_SelectedValueChanged({      

    If ($POSHGUI_cmb_raidSelect.SelectedItem -eq "EDIT Raids & Lanes, or Choose A Raid To Assign") {
        $POSHGUI_DGV_laneDifficulty.AllowUserToAddRows = $true
        $POSHGUI_DGV_laneDifficulty.DataSource = $Global:DTlaneDifficulty
        $POSHGUI_DGV_laneDifficulty.ReadOnly = $false

    } Else {
        $POSHGUI_DGV_laneDifficulty.AllowUserToAddRows = $false
        $POSHGUI_DGV_laneDifficulty.ReadOnly = $true
        $tempLaneData = $Global:DTlaneDifficulty | Where-Object {$_.Raid -eq $($POSHGUI_cmb_raidSelect.SelectedItem)}    
        $tempDT = $Global:DTlaneDifficulty.Clone()

        ForEach ($cell in $tempLaneData){
            $newRow = $tempDT.NewRow()
            $newRow.Raid = $cell.Raid
            $newrow.'Lane A' = $cell.'Lane A'
            $newrow.'Lane B' = $cell.'Lane B'
            $newrow.'Lane C' = $cell.'Lane C'
            $newrow.'Lane D' = $cell.'Lane D'
            $newrow.'Lane E' = $cell.'Lane E'
            $newrow.'Lane F' = $cell.'Lane F'
            $newrow.'Lane G' = $cell.'Lane G'
            $newrow.'Lane H' = $cell.'Lane H'
            $newrow.'Lane I' = $cell.'Lane I'
        }
        [void]$tempDT.Rows.Add($newRow)
   
        $POSHGUI_DGV_laneDifficulty.DataSource = $tempDT  
    }
})

$POSHGUI_DGV_PlayerData.Add_Validated({
    Save-Data
    $playerCount = $POSHGUI_DGV_PlayerData.RowCount
    $POSHGUI_lbl_AllianceCount.Text = " $($playerCount - 1) / 24";
})
$POSHGUI_DGV_laneDifficulty.Add_Validated({Save-Data})

$POSHGUI_cmb_AssignType.Add_SelectedValueChanged({
    If ($this.SelectedIndex -ne -1){
        $POSHGUI_btn_calcAssignment.Enabled = $true
    }
})

Load-Data

# Add Custom Code Above - Do NOT Edit This Line!
$null = $POSHGUI_MyForm.ShowDialog()

PowerShell GUI Studio (POSH)

Needing a non-application based PowerShell GUI designer, I found this one by Z.Alex on TechNet. It provided a foundation upon which I built the script below.

Features

  • Graphical PowerShell GUI Design.
  • Export AND Import of PowerShell scripts which contain GUI elements.
  • Nested controls (select the control to be nested and enter the Parent control’s name in the Parent property)
  • Uses RegEx for faster import
  • Add/Delete Control Properties
  • Self Replicating! This script was used to improve it’s own GUI! 🙂

If you have any questions, suggestions or general comments about this script, feel free to leave them below. If you modify this code and redistribute, please provide proper credit as I have done. Enjoy creating those GUIs!

PowerShell GUI Studio
PowerShell GUI Studio
GUI Designer Example
GUI Designer Example – Created with the PowerShell GUI Studio
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
# POSH GUI Studio
# Design PowerShell GUIs, Export and Import. Supports Custom Code sections to make updating
# previously created GUIs easier (those created with this tool).
# Created by Archi
# Created : 2018-07-16
# Modified: 2018-07-26
# Version 1.0
# Code base: https://gallery.technet.microsoft.com/scriptcenter/Powershell-Form-Builder-3bcaf2c7
# Many Thanks to Z.Alex for providing the foundation upon which to build.
# ===============================================================================================
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$POSHGUI_MyForm = New-Object System.Windows.Forms.Form
$POSHGUI_MyForm.Text="PowerShell GUI Studio"
Try{$POSHGUI_MyForm.Icon="C:\MyIcon\MyIcon.ico"}Catch{}
$POSHGUI_MyForm.AutoSize="True"
$POSHGUI_MyForm.StartPosition = "CenterScreen"
$POSHGUI_MyForm.Size = New-Object System.Drawing.Size(800,800)
$POSHGUI_GB_Controls = New-Object System.Windows.Forms.GroupBox
$POSHGUI_GB_Controls.Top="20"
$POSHGUI_GB_Controls.Left="10"
$POSHGUI_GB_Controls.Anchor="Left,Top"
$POSHGUI_GB_Controls.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_GB_Controls)
$POSHGUI_GB_Controls.Text="Controls"
$POSHGUI_GB_Controls.Size = New-Object System.Drawing.Size(390,445)
$POSHGUI_CB_Controls = New-Object System.Windows.Forms.ComboBox
$POSHGUI_CB_Controls.Top="20"
$POSHGUI_CB_Controls.Left="10"
$POSHGUI_CB_Controls.Anchor="Left,Top"
$POSHGUI_CB_Controls.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_CB_Controls)
$POSHGUI_CB_Controls.Text="Select"
$POSHGUI_CB_Controls.Size = New-Object System.Drawing.Size(120,23)
$POSHGUI_Btn_ControlsAdd = New-Object System.Windows.Forms.Button
$POSHGUI_Btn_ControlsAdd.Top="19"
$POSHGUI_Btn_ControlsAdd.Left="145"
$POSHGUI_Btn_ControlsAdd.Anchor="Left,Top"
$POSHGUI_Btn_ControlsAdd.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_Btn_ControlsAdd)
$POSHGUI_Btn_ControlsAdd.Text="Add"
$POSHGUI_Btn_ControlsAdd.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_Btn_ControlDelete = New-Object System.Windows.Forms.Button
$POSHGUI_Btn_ControlDelete.Top="393"
$POSHGUI_Btn_ControlDelete.Left="43"
$POSHGUI_Btn_ControlDelete.Anchor="Left,Top"
$POSHGUI_Btn_ControlDelete.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_Btn_ControlDelete)
$POSHGUI_Btn_ControlDelete.Text="Delete Selected"
$POSHGUI_Btn_ControlDelete.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_DGV_Controls = New-Object System.Windows.Forms.DataGridView
$POSHGUI_DGV_Controls.Top="70"
$POSHGUI_DGV_Controls.Left="5"
$POSHGUI_DGV_Controls.Anchor="Left,Top"
$POSHGUI_DGV_Controls.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_DGV_Controls)
$POSHGUI_DGV_Controls.RowHeadersVisible=$False
$POSHGUI_DGV_Controls.Text="DataGridView1"
$POSHGUI_DGV_Controls.Size = New-Object System.Drawing.Size(185,320)
$POSHGUI_DGV_Properties = New-Object System.Windows.Forms.DataGridView
$POSHGUI_DGV_Properties.Top="70"
$POSHGUI_DGV_Properties.Left="200"
$POSHGUI_DGV_Properties.Anchor="Left,Top"
$POSHGUI_DGV_Properties.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_DGV_Properties)
$POSHGUI_DGV_Properties.ColumnHeadersVisible=$true
$POSHGUI_DGV_Properties.RowHeadersVisible=$False
$POSHGUI_DGV_Properties.Text="DataGridView2"
$POSHGUI_DGV_Properties.Size = New-Object System.Drawing.Size(185,320)
$POSHGUI_Label1 = New-Object System.Windows.Forms.Label
$POSHGUI_Label1.Top="50"
$POSHGUI_Label1.Left="10"
$POSHGUI_Label1.Anchor="Left,Top"
$POSHGUI_Label1.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_Label1)
$POSHGUI_Label1.Text="Controls"
$POSHGUI_Label1.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_Label2 = New-Object System.Windows.Forms.Label
$POSHGUI_Label2.Top="50"
$POSHGUI_Label2.Left="200"
$POSHGUI_Label2.Anchor="Left,Top"
$POSHGUI_Label2.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_Label2)
$POSHGUI_Label2.Text="Properties"
$POSHGUI_Label2.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_GB_FormProperties = New-Object System.Windows.Forms.GroupBox
$POSHGUI_GB_FormProperties.Top="470"
$POSHGUI_GB_FormProperties.Left="10"
$POSHGUI_GB_FormProperties.Anchor="Left,Top"
$POSHGUI_GB_FormProperties.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_GB_FormProperties)
$POSHGUI_GB_FormProperties.Text="Form Properties"
$POSHGUI_GB_FormProperties.Size = New-Object System.Drawing.Size(370,105)
$POSHGUI_Label3 = New-Object System.Windows.Forms.Label
$POSHGUI_Label3.Top="22"
$POSHGUI_Label3.Left="10"
$POSHGUI_Label3.Anchor="Left,Top"
$POSHGUI_Label3.Parent="GB_FormProperties"
$POSHGUI_GB_FormProperties.Controls.Add($POSHGUI_Label3)
$POSHGUI_Label3.Text="Form Name"
$POSHGUI_Label3.Size = New-Object System.Drawing.Size(75,23)
$POSHGUI_Txt_FormName = New-Object System.Windows.Forms.TextBox
$POSHGUI_Txt_FormName.Top="18"
$POSHGUI_Txt_FormName.Left="95"
$POSHGUI_Txt_FormName.Anchor="Left,Top"
$POSHGUI_Txt_FormName.Parent="GB_FormProperties"
$POSHGUI_GB_FormProperties.Controls.Add($POSHGUI_Txt_FormName)
$POSHGUI_Txt_FormName.Text="New Form"
$POSHGUI_Txt_FormName.Size = New-Object System.Drawing.Size(125,23)
$POSHGUI_Txt_FormSizeX = New-Object System.Windows.Forms.TextBox
$POSHGUI_Txt_FormSizeX.Top="45"
$POSHGUI_Txt_FormSizeX.Left="95"
$POSHGUI_Txt_FormSizeX.Anchor="Left,Top"
$POSHGUI_Txt_FormSizeX.Parent="GB_FormProperties"
$POSHGUI_GB_FormProperties.Controls.Add($POSHGUI_Txt_FormSizeX)
$POSHGUI_Txt_FormSizeX.Text="300"
$POSHGUI_Txt_FormSizeX.Size = New-Object System.Drawing.Size(30,23)
$POSHGUI_Txt_FormSizeY = New-Object System.Windows.Forms.TextBox
$POSHGUI_Txt_FormSizeY.Top="45"
$POSHGUI_Txt_FormSizeY.Left="157"
$POSHGUI_Txt_FormSizeY.Anchor="Left,Top"
$POSHGUI_Txt_FormSizeY.Parent="GB_FormProperties"
$POSHGUI_GB_FormProperties.Controls.Add($POSHGUI_Txt_FormSizeY)
$POSHGUI_Txt_FormSizeY.Text="300"
$POSHGUI_Txt_FormSizeY.Size = New-Object System.Drawing.Size(30,23)
$POSHGUI_Label4 = New-Object System.Windows.Forms.Label
$POSHGUI_Label4.Top="50"
$POSHGUI_Label4.Left="10"
$POSHGUI_Label4.Anchor="Left,Top"
$POSHGUI_Label4.Parent="GB_FormProperties"
$POSHGUI_GB_FormProperties.Controls.Add($POSHGUI_Label4)
$POSHGUI_Label4.Text="Form Size"
$POSHGUI_Label4.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_Label5 = New-Object System.Windows.Forms.Label
$POSHGUI_Label5.Top="48"
$POSHGUI_Label5.Left="135"
$POSHGUI_Label5.Anchor="Left,Top"
$POSHGUI_Label5.Parent="GB_FormProperties"
$POSHGUI_GB_FormProperties.Controls.Add($POSHGUI_Label5)
$POSHGUI_Label5.Text="X"
$POSHGUI_Label5.Size = New-Object System.Drawing.Size(20,23)
$POSHGUI_Label6 = New-Object System.Windows.Forms.Label
$POSHGUI_Label6.Top="78"
$POSHGUI_Label6.Left="10"
$POSHGUI_Label6.Anchor="Left,Top"
$POSHGUI_Label6.Parent="GB_FormProperties"
$POSHGUI_GB_FormProperties.Controls.Add($POSHGUI_Label6)
$POSHGUI_Label6.Text="Form Icon"
$POSHGUI_Label6.Size = New-Object System.Drawing.Size(81,23)
$POSHGUI_Txt_FormIconPath = New-Object System.Windows.Forms.TextBox
$POSHGUI_Txt_FormIconPath.Top="75"
$POSHGUI_Txt_FormIconPath.Left="95"
$POSHGUI_Txt_FormIconPath.Anchor="Left,Top"
$POSHGUI_Txt_FormIconPath.Parent="GB_FormProperties"
$POSHGUI_GB_FormProperties.Controls.Add($POSHGUI_Txt_FormIconPath)
$POSHGUI_Txt_FormIconPath.Text="C:\MyIcon\MyIcon.ico"
$POSHGUI_Txt_FormIconPath.Size = New-Object System.Drawing.Size(250,23)
$POSHGUI_Btn_AddProp = New-Object System.Windows.Forms.Button
$POSHGUI_Btn_AddProp.Top="393"
$POSHGUI_Btn_AddProp.Left="230"
$POSHGUI_Btn_AddProp.Anchor="Left,Top"
$POSHGUI_Btn_AddProp.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_Btn_AddProp)
$POSHGUI_Btn_AddProp.Text="Add Property"
$POSHGUI_Btn_AddProp.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_Btn_DelProp = New-Object System.Windows.Forms.Button
$POSHGUI_Btn_DelProp.Top="418"
$POSHGUI_Btn_DelProp.Left="230"
$POSHGUI_Btn_DelProp.Anchor="Left,Top"
$POSHGUI_Btn_DelProp.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_Btn_DelProp)
$POSHGUI_Btn_DelProp.Text="Delete Property"
$POSHGUI_Btn_DelProp.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_GB_NewFormWorkSpace = New-Object System.Windows.Forms.GroupBox
$POSHGUI_GB_NewFormWorkSpace.Top="20"
$POSHGUI_GB_NewFormWorkSpace.Left="405"
$POSHGUI_GB_NewFormWorkSpace.Anchor="Left,Top"
$POSHGUI_GB_NewFormWorkSpace.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_GB_NewFormWorkSpace)
$POSHGUI_GB_NewFormWorkSpace.Text="New Form"
$POSHGUI_GB_NewFormWorkSpace.Size = New-Object System.Drawing.Size(400,400)
$POSHGUI_RTB_CustomCodeView = New-Object System.Windows.Forms.RichTextBox
$POSHGUI_RTB_CustomCodeView.Top="600"
$POSHGUI_RTB_CustomCodeView.Left="10"
$POSHGUI_RTB_CustomCodeView.Anchor="Left,Top"
$POSHGUI_RTB_CustomCodeView.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_RTB_CustomCodeView)
$POSHGUI_RTB_CustomCodeView.Text=""
$POSHGUI_RTB_CustomCodeView.Size = New-Object System.Drawing.Size(370,135)
$POSHGUI_GB_FileExportImport = New-Object System.Windows.Forms.GroupBox
$POSHGUI_GB_FileExportImport.Top="739"
$POSHGUI_GB_FileExportImport.Left="10"
$POSHGUI_GB_FileExportImport.Anchor="Left,Top"
$POSHGUI_GB_FileExportImport.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_GB_FileExportImport)
$POSHGUI_GB_FileExportImport.Text="Script Import"
$POSHGUI_GB_FileExportImport.Size = New-Object System.Drawing.Size(370,50)
$POSHGUI_BTN_ExportForm = New-Object System.Windows.Forms.Button
$POSHGUI_BTN_ExportForm.Top="20"
$POSHGUI_BTN_ExportForm.Left="45"
$POSHGUI_BTN_ExportForm.Anchor="Left,Top"
$POSHGUI_BTN_ExportForm.Parent="GB_FileExportImport"
$POSHGUI_GB_FileExportImport.Controls.Add($POSHGUI_BTN_ExportForm)
$POSHGUI_BTN_ExportForm.Text="Export Form"
$POSHGUI_BTN_ExportForm.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_BTN_ImportForm = New-Object System.Windows.Forms.Button
$POSHGUI_BTN_ImportForm.Top="20"
$POSHGUI_BTN_ImportForm.Left="220"
$POSHGUI_BTN_ImportForm.Anchor="Left,Top"
$POSHGUI_BTN_ImportForm.Parent="GB_FileExportImport"
$POSHGUI_GB_FileExportImport.Controls.Add($POSHGUI_BTN_ImportForm)
$POSHGUI_BTN_ImportForm.Text="Import Form"
$POSHGUI_BTN_ImportForm.Size = New-Object System.Drawing.Size(100,23)
$POSHGUI_Label7 = New-Object System.Windows.Forms.Label
$POSHGUI_Label7.Top="583"
$POSHGUI_Label7.Left="10"
$POSHGUI_Label7.Anchor="Left,Top"
$POSHGUI_Label7.Parent=""
$POSHGUI_MyForm.Controls.Add($POSHGUI_Label7)
$POSHGUI_Label7.Text="Custom Code"
$POSHGUI_Label7.Size = New-Object System.Drawing.Size(200,23)
$POSHGUI_Label8 = New-Object System.Windows.Forms.Label
$POSHGUI_Label8.Top="423"
$POSHGUI_Label8.Left="10"
$POSHGUI_Label8.Anchor="Left,Top"
$POSHGUI_Label8.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_Label8)
$POSHGUI_Label8.Text="Control Prefix"
$POSHGUI_Label8.Size = New-Object System.Drawing.Size(75,20)
$POSHGUI_Txt_ControlPrefix = New-Object System.Windows.Forms.TextBox
$POSHGUI_Txt_ControlPrefix.Top="419"
$POSHGUI_Txt_ControlPrefix.Left="87"
$POSHGUI_Txt_ControlPrefix.Anchor="Left,Top"
$POSHGUI_Txt_ControlPrefix.Parent="GB_Controls"
$POSHGUI_GB_Controls.Controls.Add($POSHGUI_Txt_ControlPrefix)
$POSHGUI_Txt_ControlPrefix.Text="POSHGUI_"
$POSHGUI_Txt_ControlPrefix.Size = New-Object System.Drawing.Size(100,23)
# Add Custom Code Below - Do NOT Edit This Line!
CLS
$DefaultPath = "$env:USERPROFILE\Documents"
$FormPrefix = "POSHGUI_"  # used to identify imported controls - these must be the same, here and in the impoorted PS1 for a working import
# =======================================================================
#
# Change nothing below - unless you really know what you're doing. :D
#
# =======================================================================

function mouseDown {
    $Global:mCurFirstX = ([System.Windows.Forms.Cursor]::Position.X )
    $Global:mCurFirstY = ([System.Windows.Forms.Cursor]::Position.Y )
}
 
function mouseMove ($mControlName) {
    $mCurMoveX = ([System.Windows.Forms.Cursor]::Position.X )
    $mCurMoveY = ([System.Windows.Forms.Cursor]::Position.Y )
 
    if ($Global:mCurFirstX -ne 0 -and $Global:mCurFirstY -ne 0){
     
        $mDifX = $Global:mCurFirstX - $mCurMoveX  
        $mDifY = $Global:mCurFirstY - $mCurMoveY  
         
        $this.Left = $this.Left - $mDifX
        $this.Top = $this.Top - $mDifY  
 
        $Global:mCurFirstX = $mCurMoveX  
        $Global:mCurFirstY = $mCurMoveY
    }
}
 
function mouseUP ($mControlObj) {
    $mCurUpX = ([System.Windows.Forms.Cursor]::Position.X )
    $mCurUpY = ([System.Windows.Forms.Cursor]::Position.Y )
    $Global:mCurFirstX = 0
    $Global:mCurFirstY = 0
 
    Foreach ($mElement In [array]$Global:mFormObj.Elements){
        if ($mElement.Name -eq $this.name){  
            foreach( $mProp in $mElement.Properties){              
                Switch($mProp.Name){
                    'Top'{ $mProp.Value = $this.Top}
                    'Left'{$mProp.Value = $this.Left}
                }
            }    
        }
    }    
    renewGrids
}
Function renewGrids {  
   
    $mList = New-Object System.Collections.ArrayList
    [array]$mElementsArr = $mFormObj.Elements | select Name,Type
    Try{$mList.AddRange($mElementsArr)}Catch{}
    $POSHGUI_DGV_Controls.DataSource =  $mList
    Try{$POSHGUI_DGV_Controls.Columns[1].ReadOnly = $true}Catch{}
       
    $mList2 = New-Object System.Collections.ArrayList
    Try {[array]$mPropertyArr =  $mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Properties  }Catch{}    
    Try {$mList2.AddRange($mPropertyArr)}Catch{}
    $POSHGUI_DGV_Properties.DataSource = $mList2
    Try {$POSHGUI_DGV_Properties.Columns[0].ReadOnly=$true}Catch{}    
   
}
Function DeletePropertyRow {
   
    $propRowToDelete = $POSHGUI_DGV_Properties.CurrentRow.Index
    $PropertyInfo = $POSHGUI_DGV_Properties.Rows.Item($propRowToDelete)    
    $PropertyInfoName = $($PropertyInfo.Cells.Item('Name').Value)
    [array]$Global:mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Properties = [array]$Global:mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Properties | Where-Object {$_.Name -notlike $PropertyInfoName}
    $mList2 = New-Object System.Collections.ArrayList
    Try {[array]$mPropertyArr =  $mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Properties}Catch{}  
    Try {$mList2.AddRange([array]$mPropertyArr)}Catch{}
    $POSHGUI_DGV_Properties.DataSource = $mList2
    Try {$POSHGUI_DGV_Properties.Columns[0].ReadOnly=$true}Catch{}

}
Function AddPropertyRow {
 
    $form = New-Object System.Windows.Forms.Form
    $form.Text = 'Input Property Name'
    $form.Size = New-Object System.Drawing.Size(350,200)
    $form.StartPosition = 'CenterScreen'    

    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Point(85,130)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = 'Add'
    $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
    $form.AcceptButton = $OKButton
    $form.Controls.Add($OKButton)    

    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Point(180,130)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = 'Cancel'
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    $form.CancelButton = $CancelButton
    $form.Controls.Add($CancelButton)

    $label = New-Object System.Windows.Forms.Label
    $label.Location = New-Object System.Drawing.Point(40,10)
    $label.Size = New-Object System.Drawing.Size(280,30)
    $label.Text = 'Enter the name of the Property to add. You will add the value later.'    
    $form.Controls.Add($label)
   
    $textBox = New-Object System.Windows.Forms.TextBox
    $textBox.Location = New-Object System.Drawing.Point(40,70)
    $textBox.Size = New-Object System.Drawing.Size(260,20)
    $form.Controls.Add($textBox)

    $form.Topmost = $true

    $form.Add_Shown({$textBox.Select()})
    $result = $form.ShowDialog()    
   
    if ($result -eq [System.Windows.Forms.DialogResult]::OK){
        $x = $textBox.Text
        $mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Properties +=  AddProperty -mName $x -mValue 'Edit Me'
        Try {$POSHGUI_DGV_Properties.Columns[0].ReadOnly=$true}Catch{}
        renewGrids
        repaintForm
    }
       
}
Function DeleteElement {
    [array]$Global:mFormObj.Elements = [array]$mFormObj.Elements | ?{$_.Name -notlike [array]$mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Name}
    repaintForm
    renewGrids
}

Function ClearForm {    
    [array]$Global:mFormObj.Elements = $null
    repaintForm
    renewGrids
    $POSHGUI_RTB_CustomCodeView.Clear()
}
 
Function AddProperty ($mName,$mValue){
    $mPropertyObj = New-Object PSCustomObject
    $mPropertyObj | Add-Member -Name 'Name' -MemberType NoteProperty -Value $mName
    $mPropertyObj | Add-Member -Name 'Value' -MemberType NoteProperty -Value $mValue
    return $mPropertyObj
}
 
Function ElementsChanged{        
    $mList2 = New-Object System.Collections.ArrayList
    [array]$mPropertyArr =  [array]$Global:mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Properties  
    $mList2.AddRange($mPropertyArr)
    $POSHGUI_DGV_Properties.DataSource = $mList2    
}

function ElementsEndEdit {    
    $Global:mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Name =  $POSHGUI_DGV_Controls.CurrentCell.FormattedValue    
    repaintForm    
}
Function AddElement {
   
    # Ensure we're using a listed control, not a manually entered bogus control
   
        $mPropertiesArr =@()
        $mSameType = ($mFormObj.Elements | ?{$_.Type -like $POSHGUI_CB_Controls.SelectedItem})
        If($mSameType.count -ne $NUll -and $mSameType -ne $null) {
            $mControlName=''+$POSHGUI_CB_Controls.SelectedItem+($mSameType.count+1)
        }ElseIf($mSameType.Count -eq $null -and $mSameType -ne $null){  
            $mControlName=''+$POSHGUI_CB_Controls.SelectedItem+'2'
        }Else{      
            $mControlName=''+$POSHGUI_CB_Controls.SelectedItem+'1'      
        }
 
        # Generic control properties
        $mPropertiesArr+= AddProperty 'SizeX' 100
        $mPropertiesArr+= AddProperty 'SizeY' 23
        $mPropertiesArr+= AddProperty 'Top' 5
        $mPropertiesArr+= AddProperty 'Left' 5
        $mPropertiesArr+= AddProperty 'Anchor' 'Left,Top'        
   
        # Add control specific properties
        # Each one is split out so we can add particular properties to one control but not all.
        switch ($POSHGUI_CB_Controls.SelectedItem){
 
            "TextBox"       {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName;
                            <# # We could pull in all properties for a control, but ehhh it's messy. Tackle another day...
                            ForEach ($cProp in [System.Windows.Forms.TextBox]::new() | Get-Member | Where {$_.MemberType -eq 'Property' -and $_.Name -ne 'Size' -and $_.Name -ne 'Anchor' -and $_.Name -ne 'Top' -and $_.Name -ne 'Left' -and $_.Name -ne 'Text' -and $_.Name -ne 'Parent' -and $_.Definition -like "*set*"} ){                                
                                #$cProp.ToString()
                                $cValue = ""
                                Try{$cValue = New-Object $($cProp.ToString())}Catch{}
                                $def = $cProp.Definition.Split(' ')
                                #write-host  "Property $($cProp.Name )   Value: $($cValue) "
                                $mPropertiesArr+= AddProperty $cProp.Name $cValue
                            }
                            #>
       
                            }
            "Button"        {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            "Label"         {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            'PictureBox'    {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            'CheckBox'      {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            "ComboBox"      {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }  
            'ListView'      {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            "ListBox"       {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            'RadioButton'   {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            'Panel'         {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            'GroupBox'      {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            'MaskedTextBox' {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName;
                            $mPropertiesArr+= AddProperty 'Mask' $null

                            }
            'ProgressBar'   {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            "DataGridView"  {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }  
            'DateTimePicker'{$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            'RichTextBox'   {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            'TreeView'      {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName

                            }
            'TabControl'      {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName

                            }
            'TabPage'      {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName

                            }
            'WebBrowser'    {$mPropertiesArr+= AddProperty 'Parent' $null;
                            $mPropertiesArr+= AddProperty 'Text' $mControlName
                       
                            }
            "default" {write-host 'Red Alert! Red Alert!'; break}
 
        }        

        $mElementsObj = New-Object PSCustomObject
        $mElementsObj |Add-Member -Name 'Name' -MemberType NoteProperty -Value $mControlName  
        $mElementsObj |Add-Member -Name 'Type' -MemberType NoteProperty -Value ($POSHGUI_CB_Controls.SelectedItem)
        $mElementsObj |Add-Member -Name 'Properties' -MemberType NoteProperty -Value $mPropertiesArr
        [array]$Global:mFormObj.Elements += $mElementsObj        
        renewGrids
        repaintForm      
   
}
function AddControl ($mControl) {      
   
    $mReturnControl = $null
 
    switch ($mControl.Type){
 
        "TextBox"        {$mReturnControl = New-Object System.Windows.Forms.TextBox}
        "Button"         {$mReturnControl = New-Object System.Windows.Forms.Button}  
        "Label"          {$mReturnControl = New-Object System.Windows.Forms.Label}  
        'PictureBox'     {$mReturnControl = New-Object System.Windows.Forms.PictureBox}
        'CheckBox'       {$mReturnControl = New-Object System.Windows.Forms.CheckBox}
        "ComboBox"       {$mReturnControl = New-Object System.Windows.Forms.ComboBox}  
        'ListView'       {$mReturnControl = New-Object System.Windows.Forms.ListView}
        "ListBox"        {$mReturnControl = New-Object System.Windows.Forms.ListBox}
        'RadioButton'    {$mReturnControl = New-Object System.Windows.Forms.RadioButton}
        'Panel'          {$mReturnControl = New-Object System.Windows.Forms.Panel}
        'GroupBox'       {$mReturnControl = New-Object System.Windows.Forms.GroupBox}
        'MaskedTextBox'  {$mReturnControl = New-Object System.Windows.Forms.MaskedTextBox}
        'ProgressBar'    {$mReturnControl = New-Object System.Windows.Forms.ProgressBar}
        "DataGridView"   {$mReturnControl = New-Object System.Windows.Forms.DataGridView}          
        'DateTimePicker' {$mReturnControl = New-Object System.Windows.Forms.DateTimePicker}        
        'RichTextBox'    {$mReturnControl = New-Object System.Windows.Forms.RichTextBox}
        'TreeView'       {$mReturnControl = New-Object System.Windows.Forms.TreeView}
        'WebBrowser'     {$mReturnControl = New-Object System.Windows.Forms.WebBrowser}
        'TabControl'     {$mReturnControl = New-Object System.Windows.Forms.TabControl}
        'TabPage'        {$mReturnControl = New-Object System.Windows.Forms.TabPage}
        "default"        {$mReturnControl = $null; break}
 
    }

    If ($mReturnControl -eq $null){
        Write-Host "Invalid Control Type"
        break
    }
    $mReturnControl.Name = $mControl.Name
 
    $mSizeX=$null
    $mSizeY=$null
 
    foreach ($mProperty in $mControl.Properties){
 
        switch ($mProperty.Name){
            'Text'  {Try {$mReturnControl.Text=$mProperty.Value}Catch{}}
            'SizeX' {$mSizeX=$mProperty.Value}
            'SizeY' {$mSizeY=$mProperty.Value}
            'Top'   {$mReturnControl.Top=$mProperty.Value}
            'Left'  {$mReturnControl.Left=$mProperty.Value}
            'Anchor'{$mReturnControl.Anchor=$mProperty.Value}
            'Parent'{$mReturnControl.Parent=$mProperty.Value}
            Default {Try {$mReturnControl.$($mProperty.Name) = $mProperty.Value}Catch{Write-Warning "$($PSItem.Exception.Message)"} }
        }
 
    }
 
    $mReturnControl.Size = New-Object System.Drawing.Size($mSizeX,$mSizeY)
    $mReturnControl.Add_MouseDown({MouseDown})
    $mReturnControl.Add_MouseMove({MouseMove ($mControl.Name)})
    $mReturnControl.Add_MouseUP({MouseUP})    
    Return $mReturnControl
 
}
function PropertiesEndEdit{
    foreach ($mProperty in [array]$Global:mFormObj.Elements[$POSHGUI_DGV_Controls.CurrentRow.Index].Properties){
       
            if ($mProperty.Name -eq $POSHGUI_DGV_Properties.currentrow.Cells[0].FormattedValue){
                $mProperty.Value = $POSHGUI_DGV_Properties.currentrow.Cells[1].FormattedValue
            }
    }
    repaintForm
}
Function FindParent {
    # This was the key to the nesting! Recusive search for the defined parent.
    param (
        $ParentName,
        $BaseControls
    )  

    ForEach ($childControl in $BaseControls){        
        If ($childControl.Name -eq $ParentName){
            $FoundParent = $childControl            
            Return $FoundParent
        }Else{            
            FindParent -ParentName $ParentName -BaseControls $childControl.controls
        }
    }
}

Function repaintForm {
   
    $POSHGUI_GB_NewFormWorkSpace.Size = New-Object System.Drawing.Size(($mFormObj.SizeX),($mFormObj.SizeY))
    $POSHGUI_GB_NewFormWorkSpace.controls.clear()
   
    ForEach ($mElement in [array]$Global:mFormObj.Elements){        
        $Parent = ($mElement.Properties | Where-Object {$_.Name -eq 'Parent'}).value
        If ($Parent -ne $null -and $Parent.length -gt 0 -and $Parent -eq $mElement.Name){
            write-host "Parent cannot be self!"                        
        }ElseIf ($Parent -ne $null -and $Parent.length -gt 0 -and $Parent -ne $mElement.Name){            
            $Parent = ($mElement.Properties| Where-Object {$_.Name -eq 'Parent'}).value  
            $FoundParent = FindParent -ParentName $Parent -BaseControls $($POSHGUI_GB_NewFormWorkSpace.Controls)
            If ($FoundParent){
                $FoundParent.controls.add((AddControl $mElement))
            }Else{
                Write-Host "ERROR: Unable to find specified Parent '$($Parent)' for $($mElement.Name)"
            }          
        }Else{            
            $POSHGUI_GB_NewFormWorkSpace.controls.add((AddControl $mElement))
        }      
    }    
}

Function EditFormSize ($x,$y){
    $Global:mFormObj.SizeX = $X
    $Global:mFormObj.SizeY = $Y
    repaintForm
}

Function ExportForm {  
   
    $mExportString =  'Add-Type -AssemblyName System.Windows.Forms'+"`r`n"
    $mExportString += 'Add-Type -AssemblyName System.Drawing'+"`r`n"
    $mExportString += '$'+$FormPrefix+'MyForm = New-Object System.Windows.Forms.Form'+"`r`n"
    $mExportString += '$'+$FormPrefix+'MyForm.Text="'+$Global:mFormName+'"'+"`r`n"
    $mExportString += 'Try{$'+$FormPrefix+'MyForm.Icon="'+$POSHGUI_Txt_FormIconPath.Text+'"}Catch{}'+"`r`n"
    $mExportString += '$'+$FormPrefix+'MyForm.AutoSize="True"'+"`r`n"
    $mExportString += '$'+$FormPrefix+'MyForm.StartPosition = "CenterScreen"'+"`r`n"
    $mExportString += '$'+$FormPrefix+'MyForm.Size = New-Object System.Drawing.Size('+$mFormObj.SizeX+','+$mFormObj.SizeY+')'+"`r`n"
   
    ForEach ($mElement in $mFormObj.Elements){

        $mExportString += '$'+$FormPrefix+$mElement.Name+' = New-Object System.Windows.Forms.'+$mElement.Type+''+"`r`n"
        $mPrSizeX=''
        $mPrSizeY=''
 
        ForEach ($mProperty in $mElement.Properties){
           
            #Write-Host "Property: $($mProperty.Name) Value: $($mProperty.Value)"

            If ($mProperty.Name -eq 'SizeX'){
                $mPrSizeX = $mProperty.Value
            }elseIf ($mProperty.Name -eq 'SizeY'){
                $mPrSizeY = $mProperty.Value
            }elseIf ($mElement.Type -eq 'DateTimePicker' -and $mProperty.Name -eq 'Text') {

            }elseIf ( ($mProperty.Value -eq "`$true") -or ($mProperty.Value -eq "`$false") ) {
                $mExportString += '$'+$FormPrefix+$mElement.Name+'.'+$mProperty.Name +'='+$mProperty.Value+''+"`r`n"
            }else{
                $mExportString += '$'+$FormPrefix+$mElement.Name+'.'+$mProperty.Name +'="'+$mProperty.Value+'"'+"`r`n"
            }        
       
            If ($mProperty.Name -eq 'Parent') {            
                If ($mProperty.Value -eq $null -or $mProperty.Value -le 0){
                    $mExportString += '$'+$FormPrefix+'MyForm.Controls.Add($'+$FormPrefix+$mElement.Name+')'+"`r`n"
                } Else {
                    $mExportString += '$'+$FormPrefix+$mProperty.Value+'.Controls.Add($'+$FormPrefix+$mElement.Name+')'+"`r`n"
                }
            }
       
        }

        $mExportString += '$'+$FormPrefix+$mElement.Name+'.Size = New-Object System.Drawing.Size('+$mPrSizeX+','+$mPrSizeY+')'+"`r`n"

    }
   
    $mExportString += '# Add Custom Code Below - Do NOT Edit This Line!'+"`r`n"

    If ($Global:CustomCode -ne $null){
        $mExportString += $Global:CustomCode
    }

    $mExportString += '# Add Custom Code Above - Do NOT Edit This Line!'+"`r`n"
    $mExportString += '$null = $'+$FormPrefix+'MyForm.ShowDialog()'+"`r`n"
 
    $mFileName=''
    $mFileName = Get-FileNameExport $DefaultPath
    If ($mFileName -notlike ''){            
        $mExportString | Out-File $mFileName
    }
}

Function Get-FileNameExport($initialDirectory)  {
    $SaveFileDialog = New-Object System.Windows.Forms.SaveFileDialog
    $SaveFileDialog.initialDirectory = $initialDirectory
    $SaveFileDialog.filter = “Powershell Script (*.ps1)|*.ps1|All files (*.*)|*.*
    $SaveFileDialog.ShowDialog() | Out-Null
    $SaveFileDialog.filename          
}
 
Function Get-FileNameImport($initialDirectory)  {
    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
    $OpenFileDialog.initialDirectory = $initialDirectory
    $OpenFileDialog.filter = “Powershell Script (*.ps1)|*.ps1|All files (*.*)|*.*
    $OpenFileDialog.ShowDialog() | Out-Null
    $OpenFileDialog.filename          
}

Function Import-Control{
    param (        
        $controlType,
        $ImportedData,
        $tempControl
    )
   
    $mPropertiesArr =@()
               
    $regExControlPropString = "(\$tempControl\.\w+)\s*=\s*(\S+\s{0,1}[\w|\.|\(|\)|,|`"]+)"
    $regExControlProps = [regex]::Matches($ImportedData,$regExControlPropString)

    ForEach ($controlProp in $regExControlProps){
        If ($controlProp.Captures.groups[2].value -like "*system.drawing.size*") {
            $regExSize = 'New\-Object\sSystem\.Drawing\.Size\((\d+),(\d+)\)'
            $controlSize = [regex]::Match($controlProp.Captures.groups[2].value,$regExSize)
            $controlSizeX = $controlSize.Captures.Groups[1].Value
            $controlSizeY = $controlSize.Captures.Groups[2].Value
                       
            $mPropertiesArr+= AddProperty 'SizeX' $controlSizeX
            $mPropertiesArr+= AddProperty 'SizeY' $controlSizeY

        } Else {
            $PropSplit = $controlProp.Captures.groups[1].value.split('.')
            $Prop = $PropSplit[1]
            $PropValue = $controlProp.Captures.groups[2].value.replace('"','')
            $mPropertiesArr+= AddProperty $Prop $PropValue
        }                    
    }            
 
    $mControlName = $tempControl.Replace("`$$FormPrefix",'')
    $mElementsObj = New-Object PSCustomObject
    $mElementsObj |Add-Member -Name 'Name' -MemberType NoteProperty -Value $mControlName  
    $mElementsObj |Add-Member -Name 'Type' -MemberType NoteProperty -Value $controlType
    $mElementsObj |Add-Member -Name 'Properties' -MemberType NoteProperty -Value $mPropertiesArr
    If ([array]$Global:mFormObj.Elements += $mElementsObj ){
        #Write-Host "ImportControl:: Successful"
    }Else{
        #wirte-host "ImportControl:: Failed"
    }

    renewGrids
    repaintForm    
}
Function ImportForm {

    $mFileName=''
    $mFileName = Get-FileNameImport $DefaultPath
    if ($mFileName -notlike ''){        
       
        ClearForm        
        $ImportedData = Get-Content  $mFileName        
        # Pull in custom code to add back on export          
        $customCodeStart = $ImportedData.IndexOf("# Add Custom Code Below - Do NOT Edit This Line!")
        $customCodeEnd = $ImportedData.IndexOf("# Add Custom Code Above - Do NOT Edit This Line!")
           
        for ($i= ($customCodeStart + 1); $i -lt $customCodeEnd; $i++){
                $Global:CustomCode += $ImportedData[$i] + "`r`n"
        }
        $POSHGUI_RTB_CustomCodeView.Text = $Global:CustomCode        
        #Write-Host $Global:CustomCode
        $ImportedDataWOcustomCode = $null
        ForEach ($line in $ImportedData){
            If (  ($ImportedData.IndexOf($line) -le $customCodeStart) -or  ($ImportedData.IndexOf($line) -ge $customCodeEnd) ) {
                $ImportedDataWOcustomCode += $line + "`r`n"
            }
        }

        #Get and configure Form Size
        $regExFormSize = '\$'+$FormPrefix+'MyForm\.Size\s\=\sNew\-Object\sSystem\.Drawing\.Size\((\d+),(\d+)\)'
        $formSize = [regex]::Match($ImportedDataWOcustomCode,$regExFormSize)
        $formX = $formSize.Captures.Groups[1].Value
        $formY = $formSize.Captures.Groups[2].Value
        $POSHGUI_Txt_FormSizeX.Text = $formX
        $POSHGUI_Txt_FormSizeY.Text = $formY

        EditFormSize $POSHGUI_Txt_FormSizeX.Text $POSHGUI_Txt_FormSizeY.Text
       
        renewGrids
        repaintForm
       
        # Form Controls
        $regExControls = "(\`$$($FormPrefix)[a-zA-Z0-9-_]+)\s\=\sNew\-Object\sSystem\.Windows\.Forms\.(\b(?!Form\b)\w+)"
        $formControls = [regex]::Matches($ImportedDataWOcustomCode,$regExControls)
        ForEach ($controlMatch in $formControls){
            $controlType = $controlMatch.Groups[2].Value
            $tempControl = $controlMatch.Groups[1].Value
            If ($controlType -ne 'Form'){
                Import-Control -controlType $controlType -ImportedData $ImportedDataWOcustomCode -tempControl $tempControl
            }
        }

        # Form Name
        $regExFormName = "\`$$($FormPrefix)MyForm\.Text\s*\=\s*`"(.+)`""
        $formName = [regex]::Match($ImportedDataWOcustomCode,$regExFormName)
        $getFormName = $formName.Captures.Groups[1].Value #$Matches[1].ToString()                
        $Global:mFormName = $getFormName
        $mFormNameTextBox.Text = $Global:mFormName
        $POSHGUI_GB_NewFormWorkSpace.Text = $Global:mFormName
        $POSHGUI_Txt_FormName.Text = $Global:mFormName
    }
}

Function UpdateFormName {
    $Global:mFormName = $POSHGUI_Txt_FormName.Text
    $POSHGUI_GB_NewFormWorkSpace.Text = $Global:mFormName
}

$Global:mFormName = "New Form"
$Global:CustomCode = $null
$Global:mFormObj = New-Object PSCustomObject
$Global:mFormObj | Add-Member -Name 'SizeX' -MemberType NoteProperty -Value 400  
$Global:mFormObj | Add-Member -Name 'SizeY' -MemberType NoteProperty -Value 400
$Global:mFormObj | Add-Member -Name 'Elements' -MemberType NoteProperty -Value @()
$Global:mCurFirstX = 0
$Global:mCurFirstY = 0

$null = $POSHGUI_CB_Controls.Items.Add("TextBox")
$null = $POSHGUI_CB_Controls.Items.Add("Button")
$null = $POSHGUI_CB_Controls.Items.Add("Label")
$null = $POSHGUI_CB_Controls.Items.Add("PictureBox")
$null = $POSHGUI_CB_Controls.Items.Add("CheckBox")
$null = $POSHGUI_CB_Controls.Items.Add("ComboBox")
$null = $POSHGUI_CB_Controls.Items.Add("ListView")
$null = $POSHGUI_CB_Controls.Items.Add("ListBox")
$null = $POSHGUI_CB_Controls.Items.Add("RadioButton")
$null = $POSHGUI_CB_Controls.Items.Add("Panel")
$null = $POSHGUI_CB_Controls.Items.Add("GroupBox")
$null = $POSHGUI_CB_Controls.Items.Add("MaskedTextBox")
$null = $POSHGUI_CB_Controls.Items.Add("ProgressBar")
$null = $POSHGUI_CB_Controls.Items.Add("DataGridView")
$null = $POSHGUI_CB_Controls.Items.Add("DateTimePicker")
$null = $POSHGUI_CB_Controls.Items.Add("RichTextBox")
$null = $POSHGUI_CB_Controls.Items.Add("TreeView")
$POSHGUI_CB_Controls.Sorted = $true

# Control Events
$POSHGUI_Btn_ControlsAdd.Add_Click({AddElement})
$POSHGUI_Txt_FormSizeX.Add_TextChanged({EditFormSize $POSHGUI_Txt_FormSizeX.Text $POSHGUI_Txt_FormSizeY.Text })
$POSHGUI_Txt_FormSizeY.Add_TextChanged({EditFormSize $POSHGUI_Txt_FormSizeX.Text $POSHGUI_Txt_FormSizeY.Text})
$POSHGUI_Btn_AddProp.Add_Click({AddPropertyRow})
$POSHGUI_Btn_DelProp.Add_Click({DeletePropertyRow})
$POSHGUI_Txt_FormName.Add_TextChanged({ UpdateFormName })
$POSHGUI_DGV_Controls.Add_CellContentClick({ElementsChanged})
$POSHGUI_DGV_Controls.Add_CellEndEdit({ElementsEndEdit})
$POSHGUI_DGV_Properties.Add_CellEndEdit({PropertiesEndEdit})
$POSHGUI_Btn_ControlDelete.Add_Click({DeleteElement})
$POSHGUI_BTN_ExportForm.Add_Click({ExportForm})
$POSHGUI_BTN_ImportForm.Add_Click({ImportForm})
$POSHGUI_Txt_ControlPrefix.Add_TextChanged({$FormPrefix = $POSHGUI_Txt_ControlPrefix.Text})
$POSHGUI_RTB_CustomCodeView.Add_TextChanged({
    $Global:CustomCode = $null
    ForEach ($line in $POSHGUI_RTB_CustomCodeView.Lines) {
        $Global:CustomCode += $line + "`r`n"
    }
})

# Add Custom Code Above - Do NOT Edit This Line!
$null = $POSHGUI_MyForm.ShowDialog()

RDPManager – PowerShell Based

A quick quality of life script.

Add Favorites from the drop down of Domain Controllers, or manual entry from the textbox.
Double-click a Favorite or click on Launch to open MSTSC for the selected server.
Favorites are saved in a JSON file on your desktop.

Note: Change ‘forest.local’ to the proper forest name of your environment for polling domain controllers. If you’d like to pull in all servers from your forest / domain, you’ll need to change what objects are populated into the $ADDCs variable (I.E. Use the Get-ADComputer cmdlet).

RDPManager
RDPManager
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
# PowerShell RDP Manager
# Version: 1.1
# Created: 2018-06-28
# Modified: 20-18-07-02
#=====================================================
$RDPFavs = "$env:USERPROFILE\Desktop\RDPFavs.json"
CLS

If ($host.Name -like "*ISE*"){    
    Write-Warning "Launching into a regular powershell console window"
    If ($MyInvocation.MyCommand.Path) {
        $scriptpath = $MyInvocation.MyCommand.Path -replace ' ', '` '
        Invoke-Expression "start powershell {$scriptpath}"        
    }
    break
}

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

Function Load-Favs {
  If (Test-Path -Path $RDPFavs -ErrorAction SilentlyContinue) {
    $Favs = Get-Content -Raw $RDPFavs | ConvertFrom-Json
    ForEach ($Fav in $Favs) {
        $list_favs.Items.Add($Fav)
    }
  } Else {
    $Favs = $null
  }
}

Function Save-Favs {
    $list_favs.Items | ConvertTo-Json | Out-File $RDPFavs
}

Function Start-RDP ($computername){    
    Start-Process "$env:windir\system32\mstsc.exe" -ArgumentList "/v:$computername"
}

Function Get-AllDCs {
    $ADDCs = (Get-ADForest 'forest.local' -ErrorAction SilentlyContinue -ErrorVariable errForest ).domains | ForEach {Get-ADDomain -Identity $_ -ErrorAction SilentlyContinue } | ForEach {Get-ADDomainController -Server $_.DNSRoot -Filter * -ErrorAction SilentlyContinue } | select HostName | Sort-Object
    If ($errForest) {
        $cmb_allDCs.items.Add("Error Loading DCs - $($errForest.message)")
    } Else {
        ForEach ($DC in $ADDCs) {
            $cmb_allDCs.items.Add( $dc.hostname )
        }
        $cmb_allDCs.Sorted = $true
    }
}

#region begin GUI{

$rdpManager                      = New-Object system.Windows.Forms.Form
$rdpManager.ClientSize           = '600,355'
$rdpManager.text                 = "RDP Manager"
$rdpManager.TopMost              = $false
#$rdpManager.icon                 = '\\path\to\icon.ico'

$Label1                          = New-Object system.Windows.Forms.Label
$Label1.text                     = "Favorites"
$Label1.AutoSize                 = $true
$Label1.width                    = 25
$Label1.height                   = 10
$Label1.location                 = New-Object System.Drawing.Point(12,15)
$Label1.Font                     = 'Microsoft Sans Serif,10'

$cmb_allDCs                      = New-Object system.Windows.Forms.ComboBox
$cmb_allDCs.text                 = "Select"
$cmb_allDCs.width                = 278
$cmb_allDCs.height               = 20
$cmb_allDCs.location             = New-Object System.Drawing.Point(302,42)
$cmb_allDCs.Font                 = 'Microsoft Sans Serif,10'
$cmb_allDCs.AutoSize             = $true

$Label2                          = New-Object system.Windows.Forms.Label
$Label2.text                     = "All Domain Controllers"
$Label2.AutoSize                 = $true
$Label2.width                    = 25
$Label2.height                   = 10
$Label2.location                 = New-Object System.Drawing.Point(302,18)
$Label2.Font                     = 'Microsoft Sans Serif,10'

$btn_AddToFavs                   = New-Object system.Windows.Forms.Button
$btn_AddToFavs.text              = "Add To Favs"
$btn_AddToFavs.width             = 184
$btn_AddToFavs.height            = 27
$btn_AddToFavs.location          = New-Object System.Drawing.Point(354,133)
$btn_AddToFavs.Font              = 'Microsoft Sans Serif,10'

$btn_removeFav                   = New-Object system.Windows.Forms.Button
$btn_removeFav.text              = "Remove Selected From Favs"
$btn_removeFav.width             = 195
$btn_removeFav.height            = 30
$btn_removeFav.location          = New-Object System.Drawing.Point(44,310)
$btn_removeFav.Font              = 'Microsoft Sans Serif,10'

$txt_addFav                      = New-Object system.Windows.Forms.TextBox
$txt_addFav.multiline            = $false
$txt_addFav.width                = 279
$txt_addFav.height               = 20
$txt_addFav.location             = New-Object System.Drawing.Point(302,74)
$txt_addFav.Font                 = 'Microsoft Sans Serif,10'

$Label3                          = New-Object system.Windows.Forms.Label
$Label3.text                     = "Select from above, or enter hostname manually"
$Label3.AutoSize                 = $true
$Label3.width                    = 25
$Label3.height                   = 10
$Label3.location                 = New-Object System.Drawing.Point(302,109)
$Label3.Font                     = 'Microsoft Sans Serif,10'

$btn_launch                      = New-Object system.Windows.Forms.Button
$btn_launch.text                 = "Launch RDP for Selected Fav"
$btn_launch.width                = 199
$btn_launch.height               = 30
$btn_launch.location             = New-Object System.Drawing.Point(337,310)
$btn_launch.Font                 = 'Microsoft Sans Serif,10'

$list_favs                        = New-Object system.Windows.Forms.ListBox
$list_favs.text                   = "Select"
$list_favs.width                  = 275
$list_favs.height                 = 249
$list_favs.location               = New-Object System.Drawing.Point(12,42)

$rdpManager.controls.AddRange(@($Label1,$cmb_allDCs,$Label2,$btn_AddToFavs,$btn_removeFav,$txt_addFav,$Label3,$btn_launch,$list_favs))

#region gui events {
$btn_launch.Add_Click({
    Start-RDP($list_favs.SelectedItem)
    Write-Host "Launching RDP for $($list_favs.SelectedItem)"
})
$btn_removeFav.Add_Click({    
    $list_favs.Items.RemoveAt($list_favs.SelectedIndex)
    Save-Favs
})
$btn_AddToFavs.Add_Click({    
    If ($txt_addFav.Text.Length -gt 0){
        $list_favs.Items.Add($txt_addFav.Text)
        Save-Favs
        $txt_addFav.Text = ""
    } Else {
        $list_favs.Items.Add($cmb_allDCs.SelectedItem)
        Save-Favs
    }
})

$txt_addFav.Add_KeyUp({
    if ($_.KeyCode -eq "Enter") {
        If ($txt_addFav.Text.Length -gt 0){
            $list_favs.Items.Add($txt_addFav.Text)
            Save-Favs
            $txt_addFav.Text = ""
        }
    }
})

$rdpManager.Add_Load({ Load-Favs; Get-AllDCs })
$list_favs.Add_DoubleClick({
    Start-RDP($list_favs.SelectedItem)
    Write-Host "Launching RDP for $($list_favs.SelectedItem)"
})
#endregion events }

#endregion GUI }

[void]$rdpManager.ShowDialog()

Random Password Generator

Define the password length and you’ll get a secure, randomly generated password.

1
2
$pwdLength = 15
$rngPWD = ([char[]]([char]33..[char]95) + ([char[]]([char]97..[char]126)) + 0..9 | sort {Get-Random})[0..$pwdLength] -join ''

If you need to use this for Active Directory user creation, you can convert the string to a securestring and use it like so:

1
2
$regPWDsec =  ConvertTo-SecureString $rngPWD -AsPlainText -Force
New-ADUser -Server 'blah.blah' -Path "OU=Blah,DC=blah,DC=blah" -AccountPassword $rngPWDsec -<all other defined parameters>

Add or Remove a single forest user to a group in all child domains

1
2
3
4
5
6
7
8
9
$user = Get-ADUser 'myusername' -Server 'forestdomain.com'
#==============================================================
$domains = Get-ADForest -Server 'rootdomain.com'
ForEach ($domain in $domains.Domains) {    
    $Group = Get-ADGroup -Identity 'Account Operators' -Server $domain
    # Uncomment the command below needed to add or remove
    #Add-ADGroupMember -Identity $Group -Member $user -Server $domain
    #Remove-ADGroupMember -Identity $Group -Member $user -Server $domain
}

Get-ADDomainController returns error “Directory Object not found” when using -Filter *

We recently encountered an error when using Get-ADDomainController for a domain which had a partially decommissioned domain controller (partial demotion). When running Get-ADDomainController with the * filter, it would return “Directory Object not found” and provide no other details.
Using the script below, we were able to loop through polling Active Directory for each domain controller in that domain until it failed on the faulty DC providing our first clue to the offending server.

1
(Get-ADDomain -Identity 'childdomain.domain.com').ReplicaDirectoryServers | ForEach {Get-ADDomainController -Identity $_ -Server 'childdomain.domain.com' }

Turns out there were some replication issues, visible only on the faulty DC, resulting from the partial DC demotion, requiring a metadata cleanup.

Logon Script to automatically log off users after a specified timeframe with a warning beforehand

Using this script as a PowerShell Logon Script (via GPO / GPEDIT), you can force a logoff at after a specified timeframe and give a warning to the user X minutes beforehand. You’ll want to force hide the script window using ‘-windowstyle hidden’, otherwise they could just kill it and never get logged off.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Logon Script that will auto-logoff a user after a specified amount of time has passed,
# and will give a warning of the impending logoff at a specified amount of time beforehand.
# The Warning Message has 10 second timeout so that the user can't postpone the logoff forever.
$maxTime = 8 # hours
$warnTime = 5 # minutes
$msgTimeout = 10 # seconds
$WarningMSG = "NOTICE! You will be logged off automatically in $warnTime minutes. Please save your files."
# ========================================================================================================
# Calculate Time To Sleep
$sleepyTime = $maxTime * 60 * 60
$warningTime = $warnTime * 60
Sleep -Seconds ($sleepyTime - $warningTime)
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup($WarningMSG,$msgTimeout,"Automatic Logoff Incoming...",0x0)
Sleep -Seconds $warningTime
# ADD LOGOFF CODE BELOW!
Logoff

Receive-Output – A Write-* Wrapper and Log Writer

This is a wrapper for your Write-* cmdlets. Send the message, type and file log path, and it will write out the message with the proper write-* cmdlet and log the message to the specified file.

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
<#
.Synopsis
   This is a wrapper for your Write-* cmdlets. Send the message, type and file log path, and it will write out the message with the proper write-* cmdlet and log the message to the specified file.
.DESCRIPTION
   A cmdlet / function to wrap all your write-* cmdlets
.EXAMPLE
   Receive-Output -Message "This is a test" -Type Default -Log "C:\temp\log.txt"
.EXAMPLE
   Receive-Output -Message "This is might be a test..." -Type Warning -Log "C:\temp\log.txt"
.EXAMPLE
   Receive-Output -Message "This is NOT a test!" -Type Error -Log "C:\temp\log.txt"
.EXAMPLE
   Receive-Output -M "This example uses alias parameters" -T Warning -L "C:\temp\log.txt"
.EXAMPLE
   Receive-Output -M "This example uses write-host with colors!" -T Host -L "C:\temp\log.txt" -C Magenta
#>

function Receive-Output
{
    [CmdletBinding()]
    [Alias()]
    [OutputType([int])]
    Param
    (
        # Enter the message, use quotes as needed
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [Alias("M")]
        [string]
        $Message,

        # Enter the message level
        [Parameter(Mandatory=$true,
        Position=1)]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [ValidateSet("Default", "Warning", "Error", "Debug", "Verbose", "Host")]
        [Alias("T")]
        [String]
        $Type = "Default",

        # Enter the log file path or variable containing path
        [Parameter(Mandatory=$true,
        Position=2)]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]        
        [Alias("L")]
        [String]
        $Log,

        # Enter the color for host writes
        [Parameter(
        Position=3)]    
        [Alias("C")]
        [ConsoleColor[]]
        $Colorz = [System.ConsoleColor]::White
    )

    Switch ($Type) {    
        Default  {$out = {Write-Output $Message}}
        Debug  {$out = {Write-Debug $Message -Debug}}
        Error  {$out = {Write-Error $Message}}
        Warning  {$out = {Write-Warning $Message}}            
        Verbose  {$out = {Write-Verbose $Message -Verbose}}
        Host {$out = {Write-Host $Message -ForegroundColor $Colorz}}  
    }
    # Add timestamp and write out the message to the log
    $logMessage = "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") : $Message"
    Add-Content -Value $logMessage -Path $Log  
    # Write out the message using the proper cmdlet
    Return & $out    
}

Monitor and Change File Extension for all files in folder

Monitor and Change File Extension for all files in folder.

1
2
3
4
5
6
7
8
9
10
11
12
13
$stop = $false
$i = 0
do{
    $files = Get-ChildItem -LiteralPath "C:\Users\Public\Documents" -Filter *.txt
    ForEach ($file in $files){
        $newfile = $file.FullName.Replace('.txt','.nfo')
        Rename-Item -LiteralPath $file.FullName -NewName $newfile
        $i += 1
        sleep -Milliseconds 250
    }
Write-Host renamed $i files. sleeping...
sleep -Seconds 1
}While($stop -eq $false)