-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInitialize-NetworkLab.ps1
More file actions
778 lines (618 loc) · 22.5 KB
/
Initialize-NetworkLab.ps1
File metadata and controls
778 lines (618 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
# setup lab system
<#
TO-DO:
- Add Microsoft.UI.XAML 2.71 install, a new requirement oof installing winget.
https://www.nuget.org/packages/Microsoft.UI.Xaml/
- Find a better way to install Microsoft.VCLibs.140.00.UWPDesktop
https://docs.microsoft.com/en-us/troubleshoot/cpp/c-runtime-packages-desktop-bridge
https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx
#>
[CmdletBinding()]
param (
[Parameter()]
[switch]
$RX,
[Parameter()]
[switch]
$TX,
[Parameter()]
[string[]]
$DnsServer = "192.168.1.1"
)
### FUNCTIONS ###
#region
# FUNCTION: Find-GitRelease
# PURPOSE: Calls Github API to retrieve details about the latest release. Returns a PSCustomObject with repro, version (tag_name), and download URL.
function Find-GitRelease
{
[CmdletBinding()]
param(
[string]$Repo,
[switch]$Latest
)
Write-Verbose "Find-GitRelease - Begin"
# make sure we don't try to use an insecure SSL/TLS protocol when downloading files
$secureProtocols = @()
$insecureProtocols = @( [System.Net.SecurityProtocolType]::SystemDefault,
[System.Net.SecurityProtocolType]::Ssl3,
[System.Net.SecurityProtocolType]::Tls,
[System.Net.SecurityProtocolType]::Tls11)
foreach ($protocol in [System.Enum]::GetValues([System.Net.SecurityProtocolType]))
{
if ($insecureProtocols -notcontains $protocol)
{
$secureProtocols += $protocol
}
}
[System.Net.ServicePointManager]::SecurityProtocol = $secureProtocols
if ($Latest.IsPresent)
{
Write-Verbose "Find-GitRelease - Finding latest release."
$baseApiUri = "https://api.github.com/repos/$($repo)/releases/latest"
}
else
{
Write-Verbose "Find-GitRelease - Finding all releases."
$baseApiUri = "https://api.github.com/repos/$($repo)/releases"
}
# get the available releases
Write-Verbose "Find-GitRelease - Processing repro: $repo"
Write-Verbose "Find-GitRelease - Making Github API call to: $baseApiUri"
try
{
if ($pshost.Version.Major -le 5)
{
$rawReleases = Invoke-WebRequest $baseApiUri -UseBasicParsing -EA Stop
}
elseif ($pshost.Version.Major -ge 6)
{
$rawReleases = Invoke-WebRequest $baseApiUri -EA Stop
}
else
{
return (Write-Error "Unsupported version of PowerShell...?" -EA Stop)
}
}
catch
{
return (Write-Error "Could not get GitHub releases. Error: $_" -EA Stop)
}
if ($Latest.IsPresent)
{
try
{
[version]$version = ($rawReleases.Content | ConvertFrom-Json).tag_name
}
catch
{
$version = ($rawReleases.Content | ConvertFrom-Json).tag_name
}
$dlURI = ($rawReleases.Content | ConvertFrom-Json).Assets.browser_download_url
Write-Verbose "Find-GitRelease - Processing latest version."
$releases = [PSCustomObject]@{
Repo = $repo
Version = $version
URL = $dlURI
}
Write-Verbose "Find-GitRelease - Found: $version at $dlURI"
}
else
{
$releases = @()
Write-Verbose "Find-GitRelease - Processing $($version.Count) versions."
$jsonReleases = $rawReleases.Content | ConvertFrom-Json
for ($i = 0; $i -lt $jsonReleases.Count; $i++)
{
$tmpObj = [PSCustomObject]@{
Name = $jsonReleases[$i].name
Version = [version]($jsonReleases[$i].tag_name.TrimStart("v"))
URL = $jsonReleases[$i].Assets.browser_download_url
}
$releases += $tmpObj
Remove-Variable tmpObj -EA SilentlyContinue
}
}
Write-Verbose "Find-GitRelease - End"
return $releases
} #end Find-GitRelease
# FUNCTION: Get-WebFile
# PURPOSE:
function Get-WebFile
{
[CmdletBinding()]
param (
[string]$URI,
[string]$savePath,
[string]$fileName
)
Write-Verbose "Get-WebFile - Begin"
Write-Verbose "Get-WebFile - Attempting to download: $dlUrl"
# make sure we don't try to use an insecure SSL/TLS protocol when downloading files
$secureProtocols = @()
$insecureProtocols = @( [System.Net.SecurityProtocolType]::SystemDefault,
[System.Net.SecurityProtocolType]::Ssl3,
[System.Net.SecurityProtocolType]::Tls,
[System.Net.SecurityProtocolType]::Tls11)
foreach ($protocol in [System.Enum]::GetValues([System.Net.SecurityProtocolType]))
{
if ($insecureProtocols -notcontains $protocol)
{
$secureProtocols += $protocol
}
}
[System.Net.ServicePointManager]::SecurityProtocol = $secureProtocols
try
{
Invoke-WebRequest -Uri $URI -OutFile "$savePath\$fileName"
}
catch
{
return (Write-Error "Could not download $URI`: $($Error[0].ToString())" -EA Stop)
}
Write-Verbose "Get-WebFile - File saved to: $savePath\$fileName"
Write-Verbose "Get-WebFile - End"
return "$savePath\$fileName"
} #end Get-WebFile
function Install-FromGithub
{
[CmdletBinding()]
param (
$repo,
$extension,
$savePath
)
# appx extensions
$appxExt = "msixbundle", "appx"
# download wt
$release = Find-GitRelease $repo -Latest
$fileName = "$(($repo -split '/')[-1])`.$extension"
# find the URL
$URL = $release.URL | Where-Object { $_ -match "^.*.$extension$" }
if ($URL -is [array])
{
# try to find the URL based on architecture (x64/x86) and OS (Windows)
if ([System.Environment]::Is64BitOperatingSystem)
{
$osArch = "x64"
}
else
{
$osArch = "x86"
}
$URL = $URL | Where-Object { $_ -match $osArch }
if ($URL -is [array])
{
$URL = $URL | Where-Object { $_ -match "win" }
# can do more, but this is good enough for this script
}
}
try
{
$installFile = Get-WebFile -URI $URL -savePath $savePath -fileName $fileName -EA Stop
if ($extension -in $appxExt)
{
Add-AppxPackage $installFile -EA Stop
}
elseif ($extension -eq "msi" -and $fileName -match "powershell")
{
msiexec.exe /package "$installFile" /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1
}
else
{
Start-Process "$installFile" -Wait
}
}
catch
{
return (Write-Error "$_" -EA Stop)
}
}
function Get-InstalledFonts
{
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
return ((New-Object System.Drawing.Text.InstalledFontCollection).Families)
}
function Install-Font
{
[CmdletBinding()]
param (
[Parameter()]
$Path
)
$FONTS = 0x14
$CopyOptions = 4 + 16;
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace($FONTS)
foreach ($font in $Path)
{
$CopyFlag = [String]::Format("{0:x}", $CopyOptions);
$objFolder.CopyHere($font.fullname,$CopyFlag)
}
}
#endregion FUNCTIONS
### CONSTANTS ###
#region
# where to put downloads
$savePath = "C:\Temp"
# list of exact winget app IDs to install
[array]$wingetApps = "JanDeDobbeleer.OhMyPosh", "WiresharkFoundation.Wireshark" # "Microsoft.PowerShell", "Microsoft.WindowsTerminal" -- winget tries to use MSIX which fails on 2022, so grab via github
# powershell repro and file extension
$pwshRepo = "PowerShell/PowerShell"
$pwshExt = "msi"
# Windows Terminal details
$termRepo = "Microsoft/Terminal"
# winget repro and file extension
$wingetRepo = "microsoft/winget-cli"
$wingetExt = "msixbundle"
# repro for Caskaydia Cove Nerd Font
$repoCCNF = "ryanoasis/nerd-fonts"
# name of the preferred pretty font, CaskaydiaCove NF
$fontName = "CaskaydiaCove NF"
# the zip file where CC NF is in
$fontFile = "CascadiaCode.zip"
# list of commands to add to the PowerShell profile
[string[]]$profileLines = 'Import-Module -Name Terminal-Icons',
'oh-my-posh --init --shell pwsh --config ~/jandedobbeleer.omp.json | Invoke-Expression',
'Set-PoshPrompt slimfat',
'New-PSDrive -Name Lab -PSProvider FileSystem -Root $env:USERPROFILE\Desktop\Scripts\',
'CD lab:',
'cls'
# where lab files go
$labFiles = "$env:USERPROFILE\Desktop\Scripts"
# ntttcp repo
$repoNtttcp = "microsoft/ntttcp"
# iPerf download URL
$iperfURL = "https://files.budman.pw/iperf3.10.1_64bit.zip"
# npcap URL
$npcapURL = "https://nmap.org/npcap/dist/npcap-1.60.exe"
# TAT.Net URL
$tatURL = "https://github.com/TextAnalysisTool/Releases/raw/master/TextAnalysisTool.NET.zip"
# Clumsy URL
$clumsyURL = "https://github.com/jagt/clumsy/releases/download/0.3rc4/clumsy-0.3rc4-win64-a.zip"
# VCLib URL
$vclibUrl = 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx'
$xamlUrl = 'https://www.nuget.org/packages/Microsoft.UI.Xaml/'
#endregion CONSTANTS
### MAIN ###
$null = mkdir $savePath -EA SilentlyContinue
$null = mkdir $env:USERPROFILE\Desktop\Scripts -EA SilentlyContinue
Set-Location "$env:USERPROFILE\Desktop\Scripts"
if ($TX.IsPresent)
{
# rename the computer
Rename-Computer -NewName GEARS-RX
# look for the BLUE adapter
$blueNIC = Get-NetAdapter BLUE -EA SilentlyContinue
if ($blueNIC)
{
$blueIP = Get-NetIPAddress -InterfaceAlias BLUE -AddressFamily IPv4
if ($blueIP.SuffixOrigin -ne "Manual")
{
New-NetIPAddress -InterfaceAlias BLUE -AddressFamily IPv4 -IPAddress 10.2.0.2 -PrefixLength 24 -DefaultGateway 10.2.0.1
Set-DnsClientServerAddress -InterfaceAlias BLUE -ServerAddresses $DnsServer
}
}
# look for the GREEN adapter
$greenNIC = Get-NetAdapter GREEN -EA SilentlyContinue
if ($greenNIC)
{
$greenIP = Get-NetIPAddress -InterfaceAlias GREEN -AddressFamily IPv4 -EA SilentlyContinue
if ($greenIP.SuffixOrigin -ne "Manual")
{
New-NetIPAddress -InterfaceAlias GREEN -AddressFamily IPv4 -IPAddress 10.3.0.2 -PrefixLength 24
}
}
}
elseif ($RX.IsPresent)
{
# rename the computer
Rename-Computer -NewName GEARS-RX
# look for the RED adapter
$redNIC = Get-NetAdapter RED -EA SilentlyContinue
if ($redNIC)
{
$redIP = Get-NetIPAddress -InterfaceAlias RED -AddressFamily IPv4 -EA SilentlyContinue
if ($redIP.SuffixOrigin -ne "Manual")
{
New-NetIPAddress -InterfaceAlias RED -AddressFamily IPv4 -IPAddress 10.1.0.2 -PrefixLength 24 -DefaultGateway 10.1.0.1
Set-DnsClientServerAddress -InterfaceAlias RED -ServerAddresses $DnsServer
}
}
# look for the GREEN adapter
$greenNIC = Get-NetAdapter GREEN -EA SilentlyContinue
if ($greenNIC)
{
$greenIP = Get-NetIPAddress -InterfaceAlias GREEN -AddressFamily IPv4
if ($greenIP.SuffixOrigin -ne "Manual")
{
New-NetIPAddress -InterfaceAlias GREEN -AddressFamily IPv4 -IPAddress 10.3.0.1 -PrefixLength 24
}
}
}
## install newest pwsh release ##
try
{
Install-FromGithub -repo $pwshRepo -extension $pwshExt -savePath $savePath
}
catch
{
return (Write-Error "Failed to download or install PowerShell 7+: $_" -EA Stop)
}
## install pre-req's ##
# install VCLib
try
{
$vclibFilename = 'Microsoft.VCLibs.x64.14.00.Desktop.appx'
$vclibFile = Get-WebFile -URI $vclibUrl -savePath $savePath -fileName $vclibFilename -EA Stop
Add-AppxPackage $vclibFile -EA Stop
}
catch
{
return (Write-Error "VCLib download or install failed: $_" -EA Stop)
}
# install Microsoft.UI.Xaml
$xamlPage = Invoke-WebRequest $xamlUrl -UseBasicParsing
$xamlDlUrl = $xamlPage.Links | Where-Object { $_.outerHTML -match "outbound-manual-download" } | ForEach-Object { $_.href }
try
{
$xamlFilename = 'xaml.zip'
$xamlFile = Get-WebFile -URI $xamlDlUrl -savePath $savePath -fileName $xamlFilename -EA Stop
Expand-Archive $xamlFile -EA Stop
# find the x64 installer
$xamlAppx = Get-ChildItem .\xaml -Recurse -Filter "Microsoft.UI.Xaml.*.appx" | Where-Object { $_.FullName -match "x64" }
Add-AppxPackage $xamlAppx -EA Stop
}
catch
{
return (Write-Error "Microsoft.UI.Xaml download or install failed: $_" -EA Stop)
}
## install Windows Terminal ##
# get the msixbundle for Win10
$termBundles = Find-GitRelease $termRepo | Where-Object { $_.Name -notmatch "Preview"} | Sort-Object -Property Version -Descending
$termURL = $termBundles[0].URL | Where-Object {$_ -match '^*.msixbundle$' -and $_ -match "Win10"}
try
{
$termFile = Get-WebFile -URI $termURL -savePath $savePath -fileName "terminal.msixbundle" -EA Stop
Add-AppxPackage "$termFile" -EA Stop
}
catch
{
return (Write-Error "Failed to download or install Windows Terminal: $_" -EA Stop)
}
## download and install winget from github ##
try
{
$release = Find-GitRelease $wingetRepo -Latest
$fileName = "$(($wingetRepo -split '/')[-1])`.$wingetExt"
# find the URL
$URL = $release.URL | Where-Object { $_ -match "^.*.$wingetExt$" }
$installFile = Get-WebFile -URI $URL -savePath $savePath -fileName $fileName -EA Stop
$URL2 = $release.URL | Where-Object { $_ -match "^.*.xml$" }
$fileName2 = Split-Path $url2 -Leaf
$licenseFile = Get-WebFile -URI $URL2 -savePath $savePath -fileName $fileName2 -EA Stop
Add-AppxProvisionedPackage -Online -PackagePath $installFile -LicensePath $licenseFile -Verbose -EA Stop
}
catch
{
return (Write-Error "Winget download failed: $_" -EA Stop)
}
# wait for winget to appear in the path
$count = 0
do
{
Start-Sleep 1
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
$wingetFnd = Get-Command winget -EA SilentlyContinue
$count++
} until ($wingetFnd -or $count -ge 10)
## install winget apps ##
if ($wingetFnd)
{
foreach ($app in $wingetApps)
{
# install things
winget install $app --exact --accept-package-agreements --accept-source-agreements --silent
}
# pwsh doesn't always install the first time. test and retry
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
$isPwshFnd = Get-Command pwsh -EA SilentlyContinue
if (-NOT $isPwshFnd)
{
winget install microsoft.powershell
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
$isPwshFnd = Get-Command pwsh -EA SilentlyContinue
if (-NOT $isPwshFnd)
{
return (Write-Error "PowerShell 7+ installation failed. Please install manually and try again." -EA Stop)
}
}
}
else
{
return (Write-Error "Winget installation failed: Winget not found." -EA Stop)
}
## configure PowerShell on Windows Terminal ##
# get CaskaydiaCove NF if not installed
if ($fontName -notin (Get-InstalledFonts))
{
Write-Verbose "Installing $fontName"
# get newest font
$ccnf = Find-GitRelease -repo $repoCCNF -Latest
# find the correct URL
$ccnfURL = $ccnf.URL | Where-Object {$_ -match $fontFile}
# download
try
{
$ccnfZip = Get-WebFile -URI $ccnfURL -savePath $savePath -fileName $fontFile
}
catch
{
Write-Error "Failed to download $fontFile. Please download and install $fontName manually, or the Nerd Font of your choice."
}
# extract
$extractPath = "$savePath\ccnf"
Expand-Archive -Path $ccnfZip -DestinationPath $extractPath -Force
# install fonts
Install-Font (Get-ChildItem "$extractPath" -Filter "*.ttf" -EA SilentlyContinue)
Start-Sleep 30
}
## install modules ##
[scriptblock]$cmd = {
$nugetVer = Get-PackageProvider -ListAvailable -EA SilentlyContinue | Where-Object Name -match "NuGet" | ForEach-Object { $_.Version }
[version]$minNugetVer = "2.8.5.208"
if ($nugetVer -lt $minNugetVer -or $null -eq $nugetVer)
{
Write-Verbose "Installing NuGet update."
$null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Force
}
# get module(s)
Install-Module -Name Terminal-Icons,oh-my-posh -Repository PSGallery -Scope CurrentUser -Force
}
# update $env:Path so pwsh will be found
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# install pwsh modules
pwsh -NoLogo -NoProfile -Command $cmd
# update the pwsh profile
$pwshProfilePath = pwsh -NoLogo -NoProfile -Command { $PROFILE }
$pwshProfile = Get-Content $pwshProfilePath -EA SilentlyContinue
if (-NOT (Test-path $pwshProfilePath)) { $null = New-Item $pwshProfilePath -ItemType File -Force }
foreach ($line in $profileLines)
{
if ($line -notin $pwshProfile)
{
$line | Out-File "$pwshProfilePath" -Append -Force
}
}
# assume WT is installed at this point
# launch WT once to make sure settings.json is generated
Start-Process wt -ArgumentList "-p PowerShell" -WindowStyle Minimized
Start-Sleep 10
Get-Process WindowsTerminal | Stop-Process -Force
$appxPack = Get-AppxPackage -Name "Microsoft.WindowsTerminal" -EA SilentlyContinue
$wtAppData = "$ENV:LOCALAPPDATA\Packages\$($appxPack.PackageFamilyName)\LocalState"
# export settings.json
# clean up comment lines to prevent issues with older JSON parsers (looking at you Windows PowerShell)
try
{
$wtJSON = Get-Content "$wtAppData\settings.json" -EA Stop | Where-Object { $_ -notmatch "^.*//.*$" -and $_ -ne "" -and $_ -ne $null} | ConvertFrom-Json
}
catch
{
return (Write-Error "Failed to update Windows Terminal settings." -EA Stop)
}
# change the font for PowerShell
if ($null -ne $wtJSON.profiles.list.font.face)
{
$wtJSON.profiles.list | Where-Object { $_.Name -eq "PowerShell" } | ForEach-Object { $_.Font.Face = $fontName }
}
else
{
$pwshProfile = $wtJSON.profiles.list | Where-Object { $_.Name -eq "PowerShell" }
$pwshProfile | Add-Member -NotePropertyName font -NotePropertyValue ([PSCustomObject]@{face="$fontName"})
}
# set PowerShell (pwsh) to the default profil
$pwshGUID = $wtJSON.profiles.list | Where-Object Name -eq "PowerShell" | ForEach-Object { $_.guid }
if ($pwshGUID)
{
$defaultGUID = $wtJSON.defaultProfile
if ($defaultGUID -ne $pwshGUID)
{
$wtJSON.defaultProfile = $pwshGUID
}
}
# change some WT defaults...
$evilPasteSettings = 'largePasteWarning', 'multiLinePasteWarning'
foreach ($imp in $evilPasteSettings)
{
if ($null -eq $wtJSON."$imp" -or $wtJSON."$imp" -eq $true)
{
$wtJSON | Add-Member -NotePropertyName $imp -NotePropertyValue $false -Force
}
}
# maximize wt on start
$wtJSON | Add-Member -NotePropertyName "launchMode" -NotePropertyValue "maximized" -Force
# save settings
$wtJSON | ConvertTo-Json -Depth 20 | Out-File "$wtAppData\settings.json" -Force -Encoding utf8
# get ntttcp
$ntttcpURL = Find-GitRelease -repo $repoNtttcp -Latest
try
{
$null = Get-WebFile -URI $ntttcpURL.URL -savePath $labFiles -fileName ntttcp.exe
New-NetFirewallRule -DisplayName "ntttcp (TCP-In)" -Name "ntttcp_tcp_in" -Description "Allows ntttcp traffic." -Program "$labFiles\ntttcp.exe" -Direction Inbound -Protocol TCP -Action Allow
}
catch
{
Write-Warning "Failed to download ntttcp. Please manually download."
}
# get iPerf
try
{
$iperfFile = Get-WebFile -URI $iperfURL -savePath $labFiles -fileName iperf.zip
Expand-Archive -Path $iperfFile -DestinationPath $labFiles -Force -EA SilentlyContinue
$iperfDir = Get-ChildItem $labFiles -Directory -Filter "iperf*"
Move-Item "$($iperfDir.FullName)\*" $labFiles -Force
$null = Remove-Item $($iperfDir.FullName) -Force
$null = Remove-Item $iperfFile -Force
New-NetFirewallRule -DisplayName "iPerf (TCP-In)" -Name "iperf_tcp_in" -Description "Allows iPerf traffic." -Program "$labFiles\iperf3.exe" -Direction Inbound -Protocol TCP -Action Allow
}
catch
{
Write-Warning "Failed to download iPerf. Please manually download."
}
# get npcap
try
{
$npcapFile = Get-WebFile -URI $npcapURL -savePath $labFiles -fileName npcap.exe
Start-Process "$labFiles\npcap.exe" -ArgumentList "/winpcap_mode=disabled" -Wait
$null = Remove-Item $npcapFile -Force
}
catch
{
Write-Warning "Failed to download and install npcap. Please manually download and install: $_"
}
# get TAT.NET
try
{
$tatFile = Get-WebFile -URI $tatURL -savePath $labFiles -fileName tat.zip
Expand-Archive $tatFile
Get-ChildItem .\tat -File | ForEach-Object { Move-Item $($_.FullName) -Force }
$null = Remove-Item $tatFile -Force
$null = Remove-Item .\tat -Recurse -Force
}
catch
{
Write-Warning "Failed to download and install TextAnalyzerTool. Please manually download and install: $_"
}
# get clumsy
try
{
$clumsyFile = Get-WebFile -URI $clumsyURL -savePath $labFiles -fileName clumsy.zip
Expand-Archive $clumsyFile
Get-ChildItem .\clumsy -File | ForEach-Object { Move-Item $($_.FullName) -Force }
$null = Remove-Item $clumsyFile -Force
$null = Remove-Item .\clumsy -Recurse -Force
}
catch
{
Write-Warning "Failed to download and install TextAnalyzerTool. Please manually download and install: $_"
}
# add Open With TAT
if (-NOT (Get-PSDrive -Name HKCR -EA SilentlyContinue))
{
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -Scope Local | Out-Null
}
$tatCmd = @"
"$ENV:USERPROFILE\Desktop\Scripts\TextAnalysisTool.NET.exe" "%1"
"@
$rootPath = "HKCR:\SystemFileAssociations\.txt\shell\TextAnalyzerTool.NET\Command"
New-Item $rootPath -ItemType Directory -Force
New-ItemProperty -Path $rootPath -Name "(Default)" -PropertyType String -Value $tatCmd
# ALL: Set all network connections to Private
Get-NetConnectionProfile | Where-Object NetworkCategory -eq Public | Set-NetConnectionProfile -NetworkCategory Private
# ALL: Enable File and Printer Sharing on the firewall for Private
Get-NetFirewallRule -DisplayGroup "File and Printer Sharing" | Where-Object { $_.Profile -eq "Private" -or $_.Profile -eq "Any" } | Enable-NetFirewallRule
# update and reboot
Install-PackageProvider -Name NuGet -Force
Install-Module -Name PSWindowsUpdate -MinimumVersion 2.2.0 -Force
Get-WindowsUpdate -AcceptAll -Verbose -WindowsUpdate -Install -AutoReboot
Restart-Computer -Force