-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-eGPU-Startup.ps1
More file actions
1244 lines (1055 loc) · 56.4 KB
/
Install-eGPU-Startup.ps1
File metadata and controls
1244 lines (1055 loc) · 56.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# eGPU Auto-Enable Installer/Uninstaller
# Interactive setup for automatic eGPU re-enabling at startup
# VERSION CONSTANT - Update this when releasing new versions
$SCRIPT_VERSION = "2.3.0"
<#
.SYNOPSIS
eGPU Auto-Enable Tool - Automatically re-enables eGPU after hot-plugging on Windows
.DESCRIPTION
This tool monitors your external GPU and automatically enables it whenever you reconnect it after safe-removal.
It eliminates the need to manually enable the eGPU from Device Manager.
.PARAMETER Uninstall
Removes the eGPU Auto-Enable tool from your system.
.EXAMPLE
.\Install-eGPU-Startup.ps1
Installs the eGPU Auto-Enable tool with interactive configuration.
.EXAMPLE
.\Install-eGPU-Startup.ps1 -Uninstall
Removes the eGPU Auto-Enable tool from your system.
.EXAMPLE
irm https://raw.githubusercontent.com/Bananz0/eGPUae/main/Install-eGPU-Startup.ps1 | iex
Installs the eGPU Auto-Enable tool in one line.
.NOTES
File Name : Install-eGPU-Startup.ps1
Prerequisite : PowerShell 7.0 or later
Requires Admin : Yes
Version : 2.2.0
Repository : https://github.com/Bananz0/eGPUae
#>
param(
[switch]$Uninstall
)
# Check if running as administrator
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "ERROR: This script must be run as Administrator!" -ForegroundColor Red
Write-Host "Right-click PowerShell and select 'Run as Administrator', then run this script again." -ForegroundColor Yellow
pause
exit
}
$taskName = "eGPU-AutoEnable"
$installPath = Join-Path $env:USERPROFILE ".egpu-manager"
$monitorScriptPath = Join-Path $installPath "eGPU.ps1"
$configPath = Join-Path $installPath "egpu-config.json"
# ==================== UNINSTALL MODE ====================
if ($Uninstall) {
Clear-Host
Write-Host "========================================" -ForegroundColor Red
Write-Host " eGPU Auto-Enable UNINSTALLER" -ForegroundColor Red
Write-Host "========================================`n" -ForegroundColor Red
Write-Host "This will remove:" -ForegroundColor Yellow
Write-Host " • Scheduled task: $taskName" -ForegroundColor Gray
Write-Host " • Installation folder: $installPath" -ForegroundColor Gray
Write-Host ""
$confirm = Read-Host "Are you sure you want to uninstall? (Y/N)"
if ($confirm -notlike "y*") {
Write-Host "`nUninstall cancelled." -ForegroundColor Yellow
pause
exit
}
Write-Host "`nUninstalling..." -ForegroundColor Yellow
# Stop any running instances of the script
$runningProcesses = Get-Process | Where-Object { $_.ProcessName -eq "pwsh" -and $_.CommandLine -like "*eGPU.ps1*" }
if ($runningProcesses) {
Write-Host " Stopping running eGPU monitor processes..." -ForegroundColor Gray
$runningProcesses | Stop-Process -Force -ErrorAction SilentlyContinue
}
# Remove scheduled task
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
if ($existingTask) {
Write-Host " Removing scheduled task..." -ForegroundColor Gray
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
Write-Host " ✓ Task removed" -ForegroundColor Green
}
else {
Write-Host " • Task not found (already removed)" -ForegroundColor DarkGray
}
# Remove installation folder
if (Test-Path $installPath) {
Write-Host " Removing installation folder..." -ForegroundColor Gray
# Check for eGPU power plan in config before deleting
$configPath = Join-Path $installPath "egpu-config.json"
if (Test-Path $configPath) {
try {
$config = Get-Content $configPath | ConvertFrom-Json
if ($config.PSObject.Properties.Name -contains 'eGPUPowerPlanGuid' -and $config.eGPUPowerPlanGuid) {
Write-Host " Removing eGPU power plan..." -ForegroundColor Gray
powercfg -delete $config.eGPUPowerPlanGuid 2>&1 | Out-Null
Write-Host " ✓ Power plan removed" -ForegroundColor Green
}
}
catch {
Write-Error "Failed to read or process config during uninstall: $_"
}
}
try {
Remove-Item -Path $installPath -Recurse -Force -ErrorAction Stop
Write-Host " ✓ Folder removed" -ForegroundColor Green
}
catch {
Write-Host " ⚠ Could not remove folder automatically" -ForegroundColor Yellow
Write-Host " Please manually delete: $installPath" -ForegroundColor Yellow
}
}
else {
Write-Host " • Folder not found (already removed)" -ForegroundColor DarkGray
}
Write-Host "`n========================================" -ForegroundColor Green
Write-Host " Uninstall Complete!" -ForegroundColor Green
Write-Host "========================================`n" -ForegroundColor Green
Write-Host "eGPU Auto-Enable has been removed from your system." -ForegroundColor White
Write-Host "You will need to manually enable your eGPU from Device Manager after reconnecting.`n" -ForegroundColor Gray
pause
exit
}
# ==================== INSTALL MODE ====================
Clear-Host
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " eGPU Auto-Enable INSTALLER" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
Write-Host "Installation location: $installPath`n" -ForegroundColor Gray
# Check if already installed
$alreadyInstalled = (Test-Path $installPath) -or (Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue)
if ($alreadyInstalled) {
Write-Host "⚠ eGPU Auto-Enable is already installed!" -ForegroundColor Yellow
# Check current version
$currentVersion = "Unknown"
if (Test-Path $configPath) {
try {
$config = Get-Content $configPath | ConvertFrom-Json
$currentVersion = if ($config.InstalledVersion) { $config.InstalledVersion } else { "1.0.0" }
}
catch {
Write-Error "Failed to read version from config: $_"
}
}
Write-Host "Current version: $currentVersion" -ForegroundColor Gray
Write-Host "Installer version: $SCRIPT_VERSION" -ForegroundColor Gray
Write-Host "`nWhat would you like to do?" -ForegroundColor Cyan
Write-Host " [1] Update (download and install latest version)" -ForegroundColor Gray
Write-Host " [2] Reconfigure (change settings/eGPU)" -ForegroundColor Gray
Write-Host " [3] Reinstall (fresh installation)" -ForegroundColor Gray
Write-Host " [4] Uninstall" -ForegroundColor Gray
Write-Host " [5] Cancel" -ForegroundColor Gray
Write-Host ""
$choice = Read-Host "Enter choice [1-5]"
switch ($choice) {
"1" {
# Update - download latest from GitHub
Write-Host "`nChecking for updates..." -ForegroundColor Cyan
try {
$updateUrl = "https://api.github.com/repos/Bananz0/eGPUae/releases/latest"
$releaseInfo = Invoke-RestMethod -Uri $updateUrl -ErrorAction Stop
$latestVersion = $releaseInfo.tag_name.TrimStart("v")
Write-Host "Latest version: $latestVersion" -ForegroundColor Green
if ($latestVersion -eq $currentVersion) {
Write-Host "`n✓ You already have the latest version installed!" -ForegroundColor Green
pause
exit
}
Write-Host "`nDownloading latest version..." -ForegroundColor Yellow
# Download eGPU.ps1
$eGPUUrl = "https://raw.githubusercontent.com/Bananz0/eGPUae/main/eGPU.ps1"
$installerUrl = "https://raw.githubusercontent.com/Bananz0/eGPUae/main/Install-eGPU-Startup.ps1"
$tempPath = Join-Path $env:TEMP "egpu-update"
if (-not (Test-Path $tempPath)) {
New-Item -ItemType Directory -Path $tempPath -Force | Out-Null
}
$tempEGPU = Join-Path $tempPath "eGPU.ps1"
$tempInstaller = Join-Path $tempPath "Install-eGPU-Startup.ps1"
Write-Host " Downloading eGPU.ps1..." -ForegroundColor Gray
Invoke-WebRequest -Uri $eGPUUrl -OutFile $tempEGPU -ErrorAction Stop
Write-Host " Downloading Install-eGPU-Startup.ps1..." -ForegroundColor Gray
Invoke-WebRequest -Uri $installerUrl -OutFile $tempInstaller -ErrorAction Stop
# Stop running monitor (safely)
Write-Host " Checking for running monitor..." -ForegroundColor Gray
$runningProcesses = Get-Process | Where-Object { $_.ProcessName -eq "pwsh" -and $_.CommandLine -like "*eGPU.ps1*" }
if ($runningProcesses) {
Write-Host " Stopping eGPU monitor gracefully..." -ForegroundColor Yellow
$runningProcesses | ForEach-Object {
try {
$_.CloseMainWindow() | Out-Null
Start-Sleep -Milliseconds 500
if (-not $_.HasExited) {
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
}
catch {
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
}
Start-Sleep -Seconds 2
Write-Host " ✓ Monitor stopped" -ForegroundColor Green
}
else {
Write-Host " ✓ No running monitor detected" -ForegroundColor Green
}
# Load and preserve current config
$existingConfig = $null
if (Test-Path $configPath) {
$existingConfig = Get-Content $configPath | ConvertFrom-Json
Write-Host "`n✓ Existing settings preserved:" -ForegroundColor Green
Write-Host " • eGPU: $($existingConfig.eGPU_Name)" -ForegroundColor Gray
}
# Copy new files
Write-Host "`n Installing updated files..." -ForegroundColor Gray
Copy-Item $tempEGPU -Destination $monitorScriptPath -Force
# Check for new features not in existing config
$newFeaturesAvailable = @()
if ($existingConfig) {
if (-not $existingConfig.PSObject.Properties.Name -contains 'PreventPCSleep') {
$newFeaturesAvailable += "PC Sleep Prevention"
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'eGPUDisplayTimeoutMinutes') {
$newFeaturesAvailable += "Display Timeout (OLED protection)"
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'TrackStatistics') {
$newFeaturesAvailable += "Connection Statistics"
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'AutoLaunchApps') {
$newFeaturesAvailable += "Auto-Launch Apps"
}
}
# Offer to configure new features
if ($newFeaturesAvailable.Count -gt 0) {
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " New Features Available!" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
foreach ($feature in $newFeaturesAvailable) {
Write-Host " • $feature" -ForegroundColor Yellow
}
Write-Host ""
Write-Host "Would you like to configure these new features now?" -ForegroundColor White
Write-Host " [1] Yes - Configure new features" -ForegroundColor Gray
Write-Host " [2] No - Keep defaults and finish update" -ForegroundColor Gray
Write-Host ""
$configChoice = Read-Host "Your choice [1-2]"
if ($configChoice -eq "1") {
# Set defaults for new features, then let user configure
if (-not $existingConfig.PSObject.Properties.Name -contains 'PreventPCSleep') {
$existingConfig | Add-Member -NotePropertyName 'PreventPCSleep' -NotePropertyValue $false -Force
$existingConfig | Add-Member -NotePropertyName 'PCSleepTimeoutMinutes' -NotePropertyValue $null -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'eGPUDisplayTimeoutMinutes') {
$existingConfig | Add-Member -NotePropertyName 'eGPUDisplayTimeoutMinutes' -NotePropertyValue 10 -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'EnableNotifications') {
$existingConfig | Add-Member -NotePropertyName 'EnableNotifications' -NotePropertyValue $true -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'TrackStatistics') {
$existingConfig | Add-Member -NotePropertyName 'TrackStatistics' -NotePropertyValue $true -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'AutoLaunchApps') {
$existingConfig | Add-Member -NotePropertyName 'AutoLaunchApps' -NotePropertyValue @() -Force
$existingConfig | Add-Member -NotePropertyName 'CloseLaunchersOnDisconnect' -NotePropertyValue $false -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'Statistics') {
$existingConfig | Add-Member -NotePropertyName 'Statistics' -NotePropertyValue @{
TotalConnectCount = 0
TotalConnectedTimeMinutes = 0
LastConnected = $null
LastDisconnected = $null
} -Force
}
# Save config with defaults
$existingConfig.InstalledVersion = $latestVersion
$existingConfig | ConvertTo-Json -Depth 3 | Set-Content $configPath
# Cleanup temp files
Remove-Item $tempPath -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "`n✓ Update downloaded. Launching configuration..." -ForegroundColor Green
Write-Host " (Select option 2 - Reconfigure when prompted)`n" -ForegroundColor Gray
Start-Sleep -Seconds 2
# Re-run installer in reconfigure mode
& $tempInstaller
exit
}
}
# Just update with defaults for new features
if ($existingConfig) {
# Add defaults for any missing new features
if (-not $existingConfig.PSObject.Properties.Name -contains 'PreventPCSleep') {
$existingConfig | Add-Member -NotePropertyName 'PreventPCSleep' -NotePropertyValue $false -Force
$existingConfig | Add-Member -NotePropertyName 'PCSleepTimeoutMinutes' -NotePropertyValue $null -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'eGPUDisplayTimeoutMinutes') {
$existingConfig | Add-Member -NotePropertyName 'eGPUDisplayTimeoutMinutes' -NotePropertyValue 10 -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'EnableNotifications') {
$existingConfig | Add-Member -NotePropertyName 'EnableNotifications' -NotePropertyValue $true -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'TrackStatistics') {
$existingConfig | Add-Member -NotePropertyName 'TrackStatistics' -NotePropertyValue $true -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'AutoLaunchApps') {
$existingConfig | Add-Member -NotePropertyName 'AutoLaunchApps' -NotePropertyValue @() -Force
$existingConfig | Add-Member -NotePropertyName 'CloseLaunchersOnDisconnect' -NotePropertyValue $false -Force
}
if (-not $existingConfig.PSObject.Properties.Name -contains 'Statistics') {
$existingConfig | Add-Member -NotePropertyName 'Statistics' -NotePropertyValue @{
TotalConnectCount = 0
TotalConnectedTimeMinutes = 0
LastConnected = $null
LastDisconnected = $null
} -Force
}
$existingConfig.InstalledVersion = $latestVersion
$existingConfig | ConvertTo-Json -Depth 3 | Set-Content $configPath
}
# Restart the scheduled task
$task = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
if ($task) {
Write-Host " Restarting monitor..." -ForegroundColor Gray
Start-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
}
# Cleanup
Remove-Item $tempPath -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "`n✓ Successfully updated to version $latestVersion!" -ForegroundColor Green
Write-Host "Your existing settings have been preserved." -ForegroundColor Gray
if ($newFeaturesAvailable.Count -gt 0) {
Write-Host "New features added with sensible defaults. Run installer again to configure." -ForegroundColor Gray
}
Write-Host "The eGPU monitor is now running with the latest version." -ForegroundColor Gray
}
catch {
Write-Host "`n✗ Update failed: $_" -ForegroundColor Red
Write-Host "You can manually download from: https://github.com/Bananz0/eGPUae" -ForegroundColor Yellow
}
pause
exit
}
"2" {
# Reconfigure - keep this simple, just continue with install
Write-Host "`nReconfiguring..." -ForegroundColor Yellow
Write-Host "Keeping your installation folder and proceeding to configuration.`n" -ForegroundColor Gray
# Continue to main install flow
}
"3" {
# Reinstall
Write-Host "`n========================================" -ForegroundColor Yellow
Write-Host " REINSTALLING" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Yellow
# Stop processes
Write-Host "`n[1/3] Stopping running monitor..." -ForegroundColor Gray
$runningProcesses = Get-Process | Where-Object { $_.ProcessName -eq "pwsh" -and $_.CommandLine -like "*eGPU.ps1*" }
if ($runningProcesses) {
$runningProcesses | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 1
Write-Host " ✓ Stopped" -ForegroundColor Green
}
else {
Write-Host " • No running monitor" -ForegroundColor DarkGray
}
# Remove task
Write-Host "[2/3] Removing scheduled task..." -ForegroundColor Gray
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
if ($existingTask) {
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
Write-Host " ✓ Removed" -ForegroundColor Green
}
else {
Write-Host " • No task found" -ForegroundColor DarkGray
}
# Remove folder
Write-Host "[3/3] Removing old installation..." -ForegroundColor Gray
if (Test-Path $installPath) {
Remove-Item $installPath -Recurse -Force
Write-Host " ✓ Removed" -ForegroundColor Green
}
else {
Write-Host " • No folder found" -ForegroundColor DarkGray
}
Write-Host "`nStarting fresh installation...`n" -ForegroundColor Green
Start-Sleep -Seconds 1
# Continue to main install flow
}
"4" {
# Run uninstall inline
Write-Host "`nUninstalling..." -ForegroundColor Yellow
# Stop running processes
$runningProcesses = Get-Process | Where-Object { $_.ProcessName -eq "pwsh" -and $_.CommandLine -like "*eGPU.ps1*" }
if ($runningProcesses) {
Write-Host " Stopping running eGPU monitor processes..." -ForegroundColor Gray
$runningProcesses | Stop-Process -Force -ErrorAction SilentlyContinue
}
# Remove scheduled task
$existingTask = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
if ($existingTask) {
Write-Host " Removing scheduled task..." -ForegroundColor Gray
Unregister-ScheduledTask -TaskName $taskName -Confirm:$false
Write-Host " ✓ Task removed" -ForegroundColor Green
}
else {
Write-Host " • Task not found (already removed)" -ForegroundColor DarkGray
}
# Remove installation folder
if (Test-Path $installPath) {
Write-Host " Removing installation folder..." -ForegroundColor Gray
try {
Remove-Item -Path $installPath -Recurse -Force -ErrorAction Stop
Write-Host " ✓ Folder removed" -ForegroundColor Green
}
catch {
Write-Host " ⚠ Could not remove folder automatically" -ForegroundColor Yellow
Write-Host " Please manually delete: $installPath" -ForegroundColor Yellow
}
}
else {
Write-Host " • Folder not found (already removed)" -ForegroundColor DarkGray
}
Write-Host "`n========================================" -ForegroundColor Green
Write-Host " Uninstall Complete!" -ForegroundColor Green
Write-Host "========================================`n" -ForegroundColor Green
Write-Host "eGPU Auto-Enable has been removed from your system." -ForegroundColor White
Write-Host "You will need to manually enable your eGPU from Device Manager after reconnecting.`n" -ForegroundColor Gray
pause
exit
}
default {
Write-Host "`nCancelled." -ForegroundColor Yellow
pause
exit
}
}
}
# ==================== STEP 1: GPU SELECTION ====================
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " STEP 1: Select Your eGPU" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
Write-Host "Scanning for graphics devices...`n" -ForegroundColor Yellow
$allGPUs = Get-PnpDevice -Class Display | Where-Object {
$_.FriendlyName -notlike "*Basic Display Adapter*" -and
$_.FriendlyName -notlike "*Microsoft*"
} | Sort-Object FriendlyName
if ($allGPUs.Count -eq 0) {
Write-Host "ERROR: No graphics devices found!" -ForegroundColor Red
pause
exit
}
Write-Host "Found $($allGPUs.Count) graphics device(s):`n" -ForegroundColor Green
# Display all GPUs with index
for ($i = 0; $i -lt $allGPUs.Count; $i++) {
$gpu = $allGPUs[$i]
$statusColor = if ($gpu.Status -eq "OK") { "Green" } else { "Yellow" }
$statusSymbol = if ($gpu.Status -eq "OK") { "✓" } else { "⚠" }
Write-Host " [$($i + 1)] " -NoNewline -ForegroundColor Cyan
Write-Host "$statusSymbol $($gpu.FriendlyName)" -ForegroundColor $statusColor
Write-Host " Status: $($gpu.Status)" -ForegroundColor Gray
Write-Host " Instance ID: $($gpu.InstanceId)" -ForegroundColor DarkGray
Write-Host ""
}
# Step 2: Let user select their eGPU
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "Which device is your eGPU?" -ForegroundColor Yellow
Write-Host "(The one you connect via Thunderbolt/USB-C that you want to auto-enable)" -ForegroundColor Gray
Write-Host ""
do {
$selection = Read-Host "Enter the number [1-$($allGPUs.Count)]"
$selectedIndex = [int]$selection - 1
if ($selectedIndex -lt 0 -or $selectedIndex -ge $allGPUs.Count) {
Write-Host "Invalid selection. Please enter a number between 1 and $($allGPUs.Count)." -ForegroundColor Red
}
} while ($selectedIndex -lt 0 -or $selectedIndex -ge $allGPUs.Count)
$selectedGPU = $allGPUs[$selectedIndex]
Write-Host "`nYou selected:" -ForegroundColor Green
Write-Host " $($selectedGPU.FriendlyName)" -ForegroundColor Cyan
Write-Host " Instance ID: $($selectedGPU.InstanceId)" -ForegroundColor Gray
$confirm = Read-Host "`nIs this correct? (Y/N)"
if ($confirm -notlike "y*") {
Write-Host "Installation cancelled." -ForegroundColor Yellow
pause
exit
}
# ==================== STEP 2: POWER & FEATURE SETTINGS ====================
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " STEP 2: Power & Feature Settings" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
Write-Host "Configure how your system behaves when the eGPU is connected.`n" -ForegroundColor Gray
# --- 2a: PC Sleep Prevention ---
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor DarkGray
Write-Host "PC Sleep Prevention:" -ForegroundColor Yellow
Write-Host "Keep PC awake when eGPU is connected? (for renders, downloads, etc.)" -ForegroundColor Gray
Write-Host ""
Write-Host " [1] Yes - Keep awake for 1 hour, then allow sleep" -ForegroundColor Gray
Write-Host " [2] Yes - Keep awake for 2 hours" -ForegroundColor Gray
Write-Host " [3] Yes - Keep awake for 4 hours" -ForegroundColor Gray
Write-Host " [4] Yes - Never sleep while eGPU connected" -ForegroundColor Gray
Write-Host " [5] No - Use normal sleep settings" -ForegroundColor Gray
Write-Host ""
$pcSleepChoice = Read-Host "Your choice [1-5]"
$preventPCSleep = $false
$pcSleepTimeoutMinutes = $null
switch ($pcSleepChoice) {
"1" { $preventPCSleep = $true; $pcSleepTimeoutMinutes = 60; Write-Host "✓ PC will stay awake for 1 hour" -ForegroundColor Green }
"2" { $preventPCSleep = $true; $pcSleepTimeoutMinutes = 120; Write-Host "✓ PC will stay awake for 2 hours" -ForegroundColor Green }
"3" { $preventPCSleep = $true; $pcSleepTimeoutMinutes = 240; Write-Host "✓ PC will stay awake for 4 hours" -ForegroundColor Green }
"4" { $preventPCSleep = $true; $pcSleepTimeoutMinutes = 0; Write-Host "✓ PC will never sleep while eGPU connected" -ForegroundColor Green }
default { $preventPCSleep = $false; Write-Host "✓ Normal sleep settings will apply" -ForegroundColor Green }
}
Write-Host ""
# --- 2b: Display Timeout (OLED Protection) ---
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor DarkGray
Write-Host "Display Timeout (OLED burn-in protection):" -ForegroundColor Yellow
Write-Host "When eGPU is connected, when should the display turn off?" -ForegroundColor Gray
Write-Host ""
Write-Host " [1] 5 minutes (recommended for OLED)" -ForegroundColor Green
Write-Host " [2] 10 minutes" -ForegroundColor Gray
Write-Host " [3] 15 minutes" -ForegroundColor Gray
Write-Host " [4] 30 minutes" -ForegroundColor Gray
Write-Host " [5] Never (only for non-OLED displays)" -ForegroundColor Yellow
Write-Host " [6] Use current Windows setting" -ForegroundColor DarkGray
Write-Host ""
$displayChoice = Read-Host "Your choice [1-6]"
$eGPUDisplayTimeoutMinutes = $null
switch ($displayChoice) {
"1" { $eGPUDisplayTimeoutMinutes = 5; Write-Host "✓ Display will turn off after 5 minutes" -ForegroundColor Green }
"2" { $eGPUDisplayTimeoutMinutes = 10; Write-Host "✓ Display will turn off after 10 minutes" -ForegroundColor Green }
"3" { $eGPUDisplayTimeoutMinutes = 15; Write-Host "✓ Display will turn off after 15 minutes" -ForegroundColor Green }
"4" { $eGPUDisplayTimeoutMinutes = 30; Write-Host "✓ Display will turn off after 30 minutes" -ForegroundColor Green }
"5" { $eGPUDisplayTimeoutMinutes = 0; Write-Host "⚠ Display will never turn off (not recommended for OLED)" -ForegroundColor Yellow }
default { $eGPUDisplayTimeoutMinutes = $null; Write-Host "✓ Will use current Windows display setting" -ForegroundColor Green }
}
Write-Host ""
# --- 2c: Display Timeout when Disconnected ---
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor DarkGray
Write-Host "Display Timeout (when eGPU disconnected):" -ForegroundColor Yellow
# Get current display timeout setting
$currentDisplayTimeout = "Unknown"
try {
$rawLine = powercfg /q SCHEME_CURRENT SUB_VIDEO VIDEOIDLE |
Select-String "Current AC Power Setting Index" -SimpleMatch |
ForEach-Object { $_.Line.Trim() } | Select-Object -First 1
if ($rawLine -match "0x[0-9A-Fa-f]+") {
$hex = $Matches[0]
$seconds = [Convert]::ToInt32($hex, 16)
if ($seconds -eq 0) {
$currentDisplayTimeout = "Never"
}
else {
$minutes = [math]::Ceiling($seconds / 60)
$currentDisplayTimeout = "$minutes minutes"
}
}
}
catch {
$currentDisplayTimeout = "Unable to detect"
}
# Get current lid close action
$currentLidAction = "Unknown"
$currentLidActionValue = $null
try {
$powerNamespace = @{ Namespace = 'root\cimv2\power' }
$curPlan = Get-CimInstance @powerNamespace -Class Win32_PowerPlan -Filter "IsActive = TRUE"
$lidSetting = Get-CimInstance @powerNamespace -ClassName Win32_Powersetting -Filter "ElementName = 'Lid close action'"
if ($curPlan -and $lidSetting) {
$planGuid = [Regex]::Matches($curPlan.InstanceId, "{.*}").Value
$lidGuid = [Regex]::Matches($lidSetting.InstanceID, "{.*}").Value
$pluggedInLidSetting = Get-CimInstance @powerNamespace -ClassName Win32_PowerSettingDataIndex `
-Filter "InstanceID = 'Microsoft:PowerSettingDataIndex\\$planGuid\\AC\\$lidGuid'"
if ($pluggedInLidSetting) {
$currentLidActionValue = $pluggedInLidSetting.SettingIndexValue
$currentLidAction = switch ($currentLidActionValue) {
0 { "Do Nothing" }
1 { "Sleep" }
2 { "Hibernate" }
3 { "Shut Down" }
default { "Unknown" }
}
}
}
}
catch {
$currentLidAction = "Unable to detect"
}
# Display sleep timeout preference
Write-Host "Current setting: $currentDisplayTimeout (AC Power)" -ForegroundColor Cyan
Write-Host "(Enter minutes, 0 for 'Never', or press Enter to keep current)" -ForegroundColor DarkGray
$displayTimeout = Read-Host "Minutes"
$displayTimeoutValue = $null
if (-not [string]::IsNullOrWhiteSpace($displayTimeout)) {
try {
$displayTimeoutValue = [int]$displayTimeout
if ($displayTimeoutValue -lt 0) {
Write-Host "Invalid value. Will use system default." -ForegroundColor Yellow
$displayTimeoutValue = $null
}
else {
Write-Host "✓ Will restore to $displayTimeoutValue minutes when eGPU disconnected" -ForegroundColor Green
}
}
catch {
Write-Host "Invalid input. Will use system default." -ForegroundColor Yellow
$displayTimeoutValue = $null
}
}
if ($null -eq $displayTimeoutValue) {
Write-Host "✓ Will use system's current setting when restoring" -ForegroundColor Green
}
Write-Host ""
# Lid close action preferences
Write-Host "Lid Close Action (AC Power):" -ForegroundColor Yellow
Write-Host "Current setting: $currentLidAction" -ForegroundColor Cyan
Write-Host ""
Write-Host "What should happen when you close the lid while plugged in?" -ForegroundColor Gray
Write-Host ""
Write-Host "When eGPU is CONNECTED:" -ForegroundColor Cyan
Write-Host " The script will automatically set lid action to 'Do Nothing'" -ForegroundColor Gray
Write-Host " (Prevents sleep so external monitors keep working)" -ForegroundColor DarkGray
Write-Host ""
Write-Host "When eGPU is DISCONNECTED, restore lid action to:" -ForegroundColor Cyan
Write-Host " [0] Do Nothing" -ForegroundColor Gray
Write-Host " [1] Sleep (most common)" -ForegroundColor Gray
Write-Host " [2] Hibernate" -ForegroundColor Gray
Write-Host " [3] Shut Down" -ForegroundColor Gray
Write-Host " [Enter] Keep current system setting ($currentLidAction)" -ForegroundColor DarkGray
$lidActionInput = Read-Host "`nYour choice"
$lidActionValue = $null
if (-not [string]::IsNullOrWhiteSpace($lidActionInput)) {
try {
$lidActionValue = [int]$lidActionInput
if ($lidActionValue -lt 0 -or $lidActionValue -gt 3) {
Write-Host "Invalid value. Will use system default." -ForegroundColor Yellow
$lidActionValue = $null
}
else {
$lidActionName = switch ($lidActionValue) { 0 { "Do Nothing" } 1 { "Sleep" } 2 { "Hibernate" } 3 { "Shut Down" } }
Write-Host "✓ Will restore to '$lidActionName' when eGPU disconnected" -ForegroundColor Green
}
}
catch {
Write-Host "Invalid input. Will use system default." -ForegroundColor Yellow
$lidActionValue = $null
}
}
if ($null -eq $lidActionValue) {
Write-Host "✓ Will use system's current setting when restoring" -ForegroundColor Green
# Use the detected current value as the preference
if ($null -ne $currentLidActionValue) {
$lidActionValue = $currentLidActionValue
}
}
# --- 2e: Notifications ---
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor DarkGray
Write-Host "Notifications:" -ForegroundColor Yellow
Write-Host "Show Windows notifications for eGPU connect/disconnect events?" -ForegroundColor Gray
Write-Host " ⚠ Note: Currently WIP - may not work when running as system service" -ForegroundColor DarkYellow
Write-Host ""
Write-Host " [1] Yes (recommended)" -ForegroundColor Gray
Write-Host " [2] No" -ForegroundColor Gray
Write-Host ""
$notifyChoice = Read-Host "Your choice [1-2]"
$enableNotifications = $notifyChoice -ne "2"
if ($enableNotifications) {
Write-Host "✓ Notifications enabled" -ForegroundColor Green
}
else {
Write-Host "✓ Notifications disabled" -ForegroundColor Green
}
Write-Host ""
# --- 2f: Connection Statistics ---
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor DarkGray
Write-Host "Connection Statistics:" -ForegroundColor Yellow
Write-Host "Track eGPU connection count, total connected time, etc.?" -ForegroundColor Gray
Write-Host " 📊 Local only - no data is EVER sent anywhere" -ForegroundColor DarkCyan
Write-Host ""
Write-Host " [1] Yes" -ForegroundColor Gray
Write-Host " [2] No" -ForegroundColor Gray
Write-Host ""
$statsChoice = Read-Host "Your choice [1-2]"
$trackStatistics = $statsChoice -ne "2"
if ($trackStatistics) {
Write-Host "✓ Statistics tracking enabled (local only)" -ForegroundColor Green
}
else {
Write-Host "✓ Statistics tracking disabled" -ForegroundColor Green
}
Write-Host ""
# --- 2g: Auto-Launch Apps ---
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor DarkGray
Write-Host "Auto-Launch Apps:" -ForegroundColor Yellow
Write-Host "Launch game launchers automatically when eGPU connects?" -ForegroundColor Gray
Write-Host ""
# Detect installed launchers
$launchers = @{
"Steam" = "${env:ProgramFiles(x86)}\Steam\steam.exe"
"Epic Games" = "${env:ProgramFiles(x86)}\Epic Games\Launcher\Portal\Binaries\Win64\EpicGamesLauncher.exe"
"GOG Galaxy" = "${env:ProgramFiles(x86)}\GOG Galaxy\GalaxyClient.exe"
"Playnite" = "${env:LOCALAPPDATA}\Playnite\Playnite.DesktopApp.exe"
"Ubisoft Connect" = "${env:ProgramFiles(x86)}\Ubisoft\Ubisoft Game Launcher\UbisoftConnect.exe"
"EA App" = "${env:ProgramFiles}\Electronic Arts\EA Desktop\EA Desktop\EADesktop.exe"
"Battle.net" = "${env:ProgramFiles(x86)}\Battle.net\Battle.net Launcher.exe"
}
$installedLaunchers = @{}
$launcherIndex = 1
foreach ($launcher in $launchers.GetEnumerator()) {
if (Test-Path $launcher.Value) {
$installedLaunchers[$launcherIndex] = @{ Name = $launcher.Key; Path = $launcher.Value }
Write-Host " [$launcherIndex] $($launcher.Key)" -ForegroundColor Gray
$launcherIndex++
}
}
$autoLaunchApps = @()
$closeLaunchersOnDisconnect = $false
if ($installedLaunchers.Count -gt 0) {
Write-Host " [0] None" -ForegroundColor DarkGray
Write-Host ""
Write-Host "Enter numbers separated by comma (e.g., 1,2,3) or 0 for none:" -ForegroundColor DarkGray
$launchChoice = Read-Host "Your choice"
if ($launchChoice -ne "0" -and -not [string]::IsNullOrWhiteSpace($launchChoice)) {
$choices = $launchChoice -split "," | ForEach-Object { $_.Trim() }
foreach ($choice in $choices) {
try {
$idx = [int]$choice
if ($installedLaunchers.ContainsKey($idx)) {
$autoLaunchApps += $installedLaunchers[$idx]
Write-Host " ✓ Will launch $($installedLaunchers[$idx].Name)" -ForegroundColor Green
}
}
catch { }
}
if ($autoLaunchApps.Count -gt 0) {
Write-Host ""
Write-Host "Close these apps when eGPU disconnects?" -ForegroundColor Gray
Write-Host " [1] Yes [2] No" -ForegroundColor Gray
$closeChoice = Read-Host "Your choice"
$closeLaunchersOnDisconnect = $closeChoice -eq "1"
if ($closeLaunchersOnDisconnect) {
Write-Host "✓ Apps will be closed on disconnect" -ForegroundColor Green
}
}
}
}
else {
Write-Host " No common game launchers detected" -ForegroundColor DarkGray
}
if ($autoLaunchApps.Count -eq 0) {
Write-Host "✓ No apps will be auto-launched" -ForegroundColor Green
}
Write-Host ""
# --- 2h: Safe-Eject Hotkey ---
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor DarkGray
Write-Host "Safe-Eject Hotkey:" -ForegroundColor Yellow
Write-Host "Enable a global hotkey (Ctrl+Alt+E) to safely eject the eGPU?" -ForegroundColor Gray
Write-Host " This will use your GPU vendor's official eject method if available" -ForegroundColor DarkGray
Write-Host ""
Write-Host " [1] Yes - Enable hotkey" -ForegroundColor Gray
Write-Host " [2] No" -ForegroundColor Gray
Write-Host ""
$hotkeyChoice = Read-Host "Your choice [1-2]"
$enableSafeEjectHotkey = $hotkeyChoice -eq "1"
if ($enableSafeEjectHotkey) {
Write-Host "✓ Safe-eject hotkey enabled (Ctrl+Alt+E)" -ForegroundColor Green
}
else {
Write-Host "✓ Safe-eject hotkey disabled" -ForegroundColor Green
}
Write-Host ""
# --- 2i: Pre-Disconnect Warning ---
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -ForegroundColor DarkGray
Write-Host "Pre-Disconnect Warning:" -ForegroundColor Yellow
Write-Host "Warn before safe-ejecting if GPU-intensive apps are running?" -ForegroundColor Gray
Write-Host " (Detects games, video editors, 3D apps, etc.)" -ForegroundColor DarkGray
Write-Host ""
Write-Host " [1] Yes (recommended)" -ForegroundColor Gray
Write-Host " [2] No" -ForegroundColor Gray
Write-Host ""
$warnChoice = Read-Host "Your choice [1-2]"
$preDisconnectWarning = $warnChoice -ne "2"
if ($preDisconnectWarning) {
Write-Host "✓ Pre-disconnect warning enabled" -ForegroundColor Green
}
else {
Write-Host "✓ Pre-disconnect warning disabled" -ForegroundColor Green
}
Write-Host ""
# ==================== STEP 3: POWER PLAN CREATION ====================
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host " STEP 3: eGPU Performance Power Plan" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
Write-Host "eGPU High Performance Power Plan:" -ForegroundColor Yellow
Write-Host "Create a custom power plan optimized for maximum eGPU performance?" -ForegroundColor Gray
Write-Host " - Based on High Performance plan" -ForegroundColor Gray
Write-Host " - CPU: Maximum performance (100% min/max)" -ForegroundColor Gray
Write-Host " - PCIe Link State: Maximum performance" -ForegroundColor Gray
Write-Host " - USB: No selective suspend" -ForegroundColor Gray
Write-Host " - Automatically switches when eGPU connects/disconnects" -ForegroundColor Gray
$createPowerPlan = Read-Host "`nCreate eGPU power plan? (Y/N)"
$eGPUPowerPlanGuid = $null
$originalPowerPlanGuid = $null
if ($createPowerPlan -like "y*") {
Write-Host "`nCreating eGPU High Performance power plan..." -ForegroundColor Yellow
try {
# Save the current active power plan before creating eGPU plan
$currentPlan = powercfg -GETACTIVESCHEME
if ($currentPlan -match "([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})") {
$originalPowerPlanGuid = $Matches[1]
Write-Host " Current power plan saved: $originalPowerPlanGuid" -ForegroundColor DarkGray
}
# Check if plan already exists and delete it to create fresh
$existingPlan = powercfg -list | Select-String "eGPU High Performance"
if ($existingPlan) {
# Extract GUID from existing plan
if ($existingPlan -match "([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})") {
$oldPlanGuid = $Matches[1]
Write-Host " Found existing eGPU power plan, deleting to create fresh..." -ForegroundColor Yellow
powercfg -delete $oldPlanGuid 2>&1 | Out-Null
}
}
# Create new plan based on High Performance
$result = powercfg -duplicatescheme 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c 2>&1
if ($result -match "([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})") {
$eGPUPowerPlanGuid = $Matches[1]
# Rename the power plan
powercfg -changename $eGPUPowerPlanGuid "eGPU High Performance" "Optimized for maximum eGPU performance" 2>&1 | Out-Null
# Configure for maximum performance (some settings may not be available on all systems)
# CPU: 100% minimum and maximum
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_PROCESSOR PROCTHROTTLEMIN 100 2>&1 | Out-Null
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_PROCESSOR PROCTHROTTLEMAX 100 2>&1 | Out-Null
# PCIe Link State Power Management: Off (maximum performance)
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_PCIEXPRESS ASPM 0 2>&1 | Out-Null
# USB selective suspend: Disabled
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_USB USBSELECTIVESUSPEND 0 2>&1 | Out-Null
# Hard disk: Never turn off
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_DISK DISKIDLE 0 2>&1 | Out-Null
# Display timeout: Use user's configured eGPU display timeout (OLED protection)
if ($null -ne $eGPUDisplayTimeoutMinutes) {
$displaySeconds = $eGPUDisplayTimeoutMinutes * 60
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_VIDEO VIDEOIDLE $displaySeconds 2>&1 | Out-Null
}
else {
# Default to 10 minutes if not set (safe for OLED)
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_VIDEO VIDEOIDLE 600 2>&1 | Out-Null
}
# PC Sleep: Use user's configured PC sleep timeout
if ($preventPCSleep) {
if ($null -ne $pcSleepTimeoutMinutes -and $pcSleepTimeoutMinutes -gt 0) {
$sleepSeconds = $pcSleepTimeoutMinutes * 60
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_SLEEP STANDBYIDLE $sleepSeconds 2>&1 | Out-Null
}
else {
# Never sleep
powercfg -setacvalueindex $eGPUPowerPlanGuid SUB_SLEEP STANDBYIDLE 0 2>&1 | Out-Null
}
}
# Only activate if eGPU is currently connected and working
$isEGPUConnected = $selectedGPU.Status -eq "OK"
if ($isEGPUConnected) {
powercfg -setactive $eGPUPowerPlanGuid | Out-Null
Write-Host "✓ Created and activated eGPU High Performance power plan" -ForegroundColor Green
Write-Host " (eGPU is connected)" -ForegroundColor DarkGray
}
else {
Write-Host "✓ Created eGPU High Performance power plan" -ForegroundColor Green
Write-Host " (Will activate automatically when eGPU connects)" -ForegroundColor DarkGray
}
}
else {