-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtechtools_actions.ps1
More file actions
2566 lines (2267 loc) · 118 KB
/
Copy pathtechtools_actions.ps1
File metadata and controls
2566 lines (2267 loc) · 118 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
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateSet(
"dism_scanhealth",
"dism_checkhealth",
"dism_restorehealth",
"dism_componentcleanup",
"sfc_scannow",
"sysinfo",
"net_reset",
"wu_reset",
"temp_cleanup",
"upgrade_pro",
"power_high",
"chkdsk_c",
"bitlocker_disable",
"battery_info",
"device_driver_check",
"disk_space_check",
"pending_reboot_check",
"disk_health_check",
"disk_event_check",
"network_diag",
"wu_diag",
"event_diag",
"security_status",
"dump_check",
"startup_overview",
"service_diag",
"printer_diag",
"printer_queue_clear",
"printer_test_page",
"time_diag",
"time_resync",
"report_export",
"secureboot_ca_install"
)]
[string]$Action
)
$ErrorActionPreference = "Stop"
Write-Output "TechTools PowerShell-Aktionen"
Write-Output "==========================="
Write-Output "Action: $Action"
Write-Output ""
function Write-ToolStatus {
param(
[Parameter(Mandatory = $true)]
[ValidateSet("OK", "INFO", "WARNUNG", "KRITISCH", "FEHLER")]
[string]$Level,
[Parameter(Mandatory = $true)]
[string]$Message
)
Write-Output ("[{0}] {1}" -f $Level, $Message)
}
function Format-ToolSize {
param([Nullable[double]]$Bytes)
if ($null -eq $Bytes) { return "Nicht verfügbar" }
if ($Bytes -ge 1TB) { return ("{0:N1} TB" -f ($Bytes / 1TB)) }
if ($Bytes -ge 1GB) { return ("{0:N1} GB" -f ($Bytes / 1GB)) }
if ($Bytes -ge 1MB) { return ("{0:N1} MB" -f ($Bytes / 1MB)) }
return ("{0:N0} B" -f $Bytes)
}
function Get-DeviceProblemText {
param([int]$Code)
switch ($Code) {
1 { "Gerät ist nicht korrekt konfiguriert." }
10 { "Gerät kann nicht gestartet werden." }
18 { "Treiber sollte neu installiert werden." }
22 { "Gerät ist deaktiviert." }
24 { "Gerät ist nicht vorhanden oder funktioniert nicht korrekt." }
28 { "Für dieses Gerät ist kein Treiber installiert." }
31 { "Ein benÖer Treiber kann nicht geladen werden." }
32 { "Der Treiberdienst ist deaktiviert." }
43 { "Das Gerät hat Windows einen Fehler gemeldet." }
45 { "Gerät ist derzeit nicht angeschlossen." }
48 { "Treiber wurde wegen Problemen blockiert." }
52 { "Digitale Signatur kann nicht Ü werden." }
default { "Windows meldet Problemcode $Code." }
}
}
function Get-DeviceProblemLevel {
param([int]$Code)
switch ($Code) {
22 { "INFO" }
45 { "INFO" }
43 { "KRITISCH" }
default { "WARNUNG" }
}
}
function Test-PendingRebootReason {
$reasons = New-Object System.Collections.Generic.List[string]
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") {
$reasons.Add("Component Based Servicing")
}
if (Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") {
$reasons.Add("Windows Update")
}
$sessionManager = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -ErrorAction SilentlyContinue
if ($sessionManager -and $sessionManager.PendingFileRenameOperations) {
$reasons.Add("Ausstehende Dateioperationen")
}
$computerName = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" -ErrorAction SilentlyContinue
$activeName = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName" -ErrorAction SilentlyContinue
if ($computerName -and $activeName -and $computerName.ComputerName -ne $activeName.ComputerName) {
$reasons.Add("Computerumbenennung")
}
return $reasons
}
switch ($Action) {
# -------------------------------------------------------------------------
# 1: DISM /ScanHealth
# -------------------------------------------------------------------------
"dism_scanhealth" {
Write-Output "Windows Komponentenspeicher wird geprüft (ScanHealth) ..."
Write-Output ""
try {
DISM /Online /Cleanup-Image /ScanHealth
$code = $LASTEXITCODE
Write-Output ""
if ($code -ne 0) {
Write-Output "DISM /ScanHealth beendet. Rückgabecode: $code"
} else {
Write-Output "DISM /ScanHealth erfolgreich abgeschlossen."
}
exit $code
}
catch {
Write-Output ""
Write-Output "FEHLER bei DISM /ScanHealth:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 2: DISM /CheckHealth
# -------------------------------------------------------------------------
"dism_checkhealth" {
Write-Output "Prüfe, ob Windows als beschädigt markiert ist (CheckHealth) ..."
Write-Output ""
try {
DISM /Online /Cleanup-Image /CheckHealth
$code = $LASTEXITCODE
Write-Output ""
if ($code -ne 0) {
Write-Output "DISM /CheckHealth beendet. Rückgabecode: $code"
} else {
Write-Output "DISM /CheckHealth erfolgreich abgeschlossen."
}
exit $code
}
catch {
Write-Output ""
Write-Output "FEHLER bei DISM /CheckHealth:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# DISM /RestoreHealth - mit Klartext-Ergebnis
# -------------------------------------------------------------------------
"dism_restorehealth" {
Write-Output "Automatische Reparatur des Windows-Komponentenspeichers wird durchgeführt ..."
Write-Output ""
try {
$output = DISM /Online /Cleanup-Image /RestoreHealth
Write-Output $output
Write-Output ""
if ($output -match 'Der Wiederherstellungsvorgang wurde erfolgreich abgeschlossen') {
Write-Output "Ergebnis: Der Windows-Komponentenspeicher wurde erfolgreich repariert."
exit 0
}
elseif ($output -match 'Keine Beschädigung des Komponentenspeichers erkannt') {
Write-Output "Ergebnis: Keine Beschädigungen gefunden. Keine Reparatur erforderlich."
exit 0
}
elseif ($output -match 'Fehler') {
Write-Output "Ergebnis: Reparatur fehlgeschlagen."
Write-Output "Empfehlung: Windows Update / Installationsmedium prüfen."
exit 2
}
else {
Write-Output "Ergebnis: Unklarer DISM-Status. Bitte Log prüfen."
exit 1
}
}
catch {
Write-Output ""
Write-Output "FEHLER bei DISM RestoreHealth:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 4: DISM StartComponentCleanup
# -------------------------------------------------------------------------
"dism_componentcleanup" {
Write-Output "Abgelöste Startkomponenten werden bereinigt (StartComponentCleanup) ..."
Write-Output ""
try {
DISM /Online /Cleanup-Image /StartComponentCleanup
$code = $LASTEXITCODE
if ($code -ne 0) {
Write-Output "DISM /StartComponentCleanup beendet. Rückgabecode: $code"
} else {
Write-Output "DISM /StartComponentCleanup erfolgreich abgeschlossen."
}
exit $code
}
catch {
Write-Output ""
Write-Output "FEHLER bei DISM /StartComponentCleanup:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# SFC /SCANNOW - finale, robuste Auswertung
# -------------------------------------------------------------------------
"sfc_scannow" {
Write-Output "Systemdateien werden mit sfc /scannow geprüft und ggf. repariert ..."
Write-Output ""
try {
# SFC einfach laufen lassen, Ausgabe geht direkt ins Log
cmd /c "chcp 850 >nul & sfc /scannow"
$code = $LASTEXITCODE
Write-Output ""
Write-Output "sfc /scannow beendet. Rückgabecode: $code"
exit $code
}
catch {
Write-Output ""
Write-Output "FEHLER bei sfc /scannow:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# CHKDSK C: - Reparaturmodus beim nächsten Neustart planen
# -------------------------------------------------------------------------
"chkdsk_c" {
Write-Output "CHKDSK-Reparatur für Laufwerk C: wird vorbereitet ..."
Write-Output ""
Write-Output "Das Dateisystem wird beim nächsten Neustart überprüft und repariert."
Write-Output "Hinweis: Der Vorgang kann je nach Laufwerksgröße einige Zeit dauern."
Write-Output ""
try {
# Dirty-Bit setzen -> Windows führt beim nächsten Boot Autochk (CHKDSK /F) aus.
fsutil dirty set C: | Out-Null
Write-Output "CHKDSK wurde erfolgreich für den nächsten Systemstart eingeplant."
Write-Output "Bitte den Computer neu starten, damit die Überprüfung durchgeführt wird."
exit 0
}
catch {
Write-Output ""
Write-Output "FEHLER beim Einplanen von CHKDSK:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 6: Systeminformationen → Report auf Desktop + Notepad
# -------------------------------------------------------------------------
"sysinfo" {
Write-Output "Erstelle Systeminformationen-Report auf dem Desktop ..."
Write-Output ""
try {
$desktopPath = [Environment]::GetFolderPath("Desktop")
$filePath = Join-Path $desktopPath "TechTools_Systeminfo.txt"
$os = Get-CimInstance Win32_OperatingSystem
$cpu = Get-CimInstance Win32_Processor | Select-Object -First 1
$gpus = Get-CimInstance Win32_VideoController
$board = Get-CimInstance Win32_BaseBoard | Select-Object -First 1
$bios = Get-CimInstance Win32_BIOS | Select-Object -First 1
$memModules = Get-CimInstance Win32_PhysicalMemory
$disks = Get-CimInstance Win32_DiskDrive
$output = @"
Systeminformationen
Betriebssystem
Edition = $($os.Caption)
Build-Nummer = $($os.Version)
Prozessor
Name = $($cpu.Name)
Kerne/Threads = $($cpu.NumberOfCores) C / $($cpu.NumberOfLogicalProcessors) T
Sockel = $($cpu.SocketDesignation)
"@
if ($gpus) {
foreach ($gpu in $gpus) {
$output += @"
Grafik
Chip-Name = $($gpu.Name)
Treiberversion= $($gpu.DriverVersion)
Treiberdatum = $($gpu.DriverDate)
"@
}
}
if ($board -and $bios) {
$output += @"
Mainboard
Hersteller = $($board.Manufacturer)
Modell = $($board.Product)
Seriennummer = $($board.SerialNumber)
Revision = $($board.Version)
BIOS-Version = $($bios.SMBIOSBIOSVersion)
"@
}
if ($memModules) {
$output += "Arbeitsspeicher`n"
foreach ($m in $memModules) {
$sizeGB = [math]::Round($m.Capacity / 1GB, 0)
$output += @"
Modul
Hersteller = $($m.Manufacturer)
Modell = $($m.PartNumber)
Seriennummer = $($m.SerialNumber)
Steckplatz = $($m.DeviceLocator)
Speicher = ${sizeGB} GB
Taktfrequenz = $($m.ConfiguredClockSpeed) MHz
"@
}
}
if ($disks) {
$output += "Laufwerke`n"
foreach ($disk in $disks) {
$sizeGB = [math]::Round($disk.Size / 1GB, 0)
$volName = ""
$volLetter = ""
try {
$partitions = Get-CimInstance -Query "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($disk.DeviceID)'} WHERE AssocClass=Win32_DiskDriveToDiskPartition"
foreach ($part in $partitions) {
$logical = Get-CimInstance -Query "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($part.DeviceID)'} WHERE AssocClass=Win32_LogicalDiskToPartition" | Select-Object -First 1
if ($logical) {
$volLetter = $logical.DeviceID
$volName = $logical.VolumeName
break
}
}
} catch {
# ignorieren
}
$output += @"
Datenträger
Modell = $($disk.Model)
Größe = ${sizeGB} GB
Schnittstelle = $($disk.InterfaceType)
Laufwerk = $volLetter
Volumename = $volName
"@
}
}
Set-Content -Path $filePath -Encoding UTF8 -Value $output
Start-Process "notepad.exe" -ArgumentList "`"$filePath`""
Write-Output ""
Write-Output "Systeminformationen wurden nach:"
Write-Output " $filePath"
Write-Output "geschrieben und in Notepad geöffnet."
exit 0
}
catch {
Write-Output ""
Write-Output "FEHLER beim Erstellen des Systeminfo-Reports:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 7: Netzwerkeinstellungen zurücksetzen
# -------------------------------------------------------------------------
"net_reset" {
Write-Output "Netzwerk-Reset wird ausgeführt ..."
Write-Output ""
try {
# 1) Adapter auf DHCP setzen (IPv4/IPv6/DNS)
Write-Output "1/6: IPv4/IPv6 & DNS aller aktiven Adapter auf DHCP setzen ..."
$networkAdapters = Get-NetAdapter | Where-Object { $_.Status -eq 'Up' }
foreach ($adapter in $networkAdapters) {
netsh interface ip set address name="$($adapter.Name)" source=dhcp | Out-Null
netsh interface ip set dns name="$($adapter.Name)" source=dhcp | Out-Null
netsh interface ipv6 set dnsservers "$($adapter.Name)" dhcp | Out-Null
}
# 2) Winsock-Katalog zurücksetzen
Write-Output "2/6: Winsock-Katalog zurücksetzen ..."
netsh winsock reset | Out-Null
# 3) TCP/IP-Stack zurücksetzen
Write-Output "3/6: TCP/IP-Einstellungen auf Standard zurücksetzen ..."
netsh int ip reset | Out-Null
# 4) IP erneuern + DNS-Cache leeren
Write-Output "4/6: IP-Adresse erneuern & DNS-Cache leeren ..."
ipconfig /release | Out-Null
ipconfig /renew | Out-Null
ipconfig /flushdns | Out-Null
# 5) Windows-Firewall zurücksetzen
Write-Output "5/6: Windows-Firewall auf Standardregeln zurücksetzen ..."
netsh advfirewall reset | Out-Null
# 6) Proxy zurücksetzen
Write-Output "6/6: Proxy-Einstellungen zurücksetzen ..."
netsh winhttp reset proxy | Out-Null
$regPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
if (Test-Path $regPath) {
Set-ItemProperty -Path $regPath -Name AutoConfigURL -Value "" -ErrorAction SilentlyContinue
Set-ItemProperty -Path $regPath -Name ProxyEnable -Value 0 -ErrorAction SilentlyContinue
Set-ItemProperty -Path $regPath -Name AutoDetect -Value 1 -ErrorAction SilentlyContinue
}
Write-Output ""
Write-Output "Netzwerk-Reset abgeschlossen. Ein Neustart des Systems wird empfohlen."
exit 0
}
catch {
Write-Output ""
Write-Output "FEHLER beim Netzwerk-Reset:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 8: Windows Update Komponenten resetten
# -------------------------------------------------------------------------
"wu_reset" {
Write-Output "Windows-Update-Komponenten werden zurückgesetzt ..."
Write-Output ""
$ErrorActionPreference = 'SilentlyContinue'
try {
attrib -h -r -s "$env:windir\system32\catroot2" 2>$null
attrib -h -r -s "$env:windir\system32\catroot2\*.*" 2>$null
Write-Output "• Dienste anhalten (wuauserv, CryptSvc, BITS, msiserver) ..."
Stop-Service -Name wuauserv -Force
Stop-Service -Name CryptSvc -Force
Stop-Service -Name BITS -Force
Stop-Service -Name msiserver -Force
Write-Output "• Cache-Ordner umbenennen ..."
Rename-Item -Path "$env:windir\SoftwareDistribution" -NewName "SoftwareDistribution.old" -ErrorAction SilentlyContinue
Rename-Item -Path "$env:windir\system32\catroot2" -NewName "catroot2.old" -ErrorAction SilentlyContinue
Write-Output "• Dienste wieder starten ..."
Start-Service -Name wuauserv
Start-Service -Name CryptSvc
Start-Service -Name BITS
Start-Service -Name msiserver
Write-Output ""
Write-Output "Windows-Update-Komponenten wurden zurückgesetzt."
exit 0
}
catch {
Write-Output ""
Write-Output "FEHLER beim Windows-Update-Reset:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 9: Temporäre Dateien bereinigen (Datenträgerbereinigung)
# -------------------------------------------------------------------------
"temp_cleanup" {
Write-Output "Bereinigung temporärer Dateien mit Datenträgerbereinigung ..."
Write-Output ""
try {
$Keys = @(
"Active Setup Temp Folders",
"Downloaded Program Files",
"Internet Cache Files",
"Memory Dump Files",
"Old ChkDsk Files",
"Previous Installations",
"Recycle Bin",
"Service Pack Cleanup",
"Setup Log Files",
"System error memory dump files",
"System error minidump files",
"Temporary Files",
"Temporary Setup Files",
"Thumbnail Cache",
"Update Cleanup",
"Upgrade Discarded Files",
"Windows Error Reporting Archive Files",
"Windows Error Reporting Queue Files",
"Windows Error Reporting System Archive Files",
"Windows Error Reporting System Queue Files",
"Windows Upgrade Log Files"
)
$BaseKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
Write-Output "• Cleanup-Kategorien für cleanmgr (/sagerun:200) aktivieren ..."
foreach ($Key in $Keys) {
New-ItemProperty -Path "$BaseKey\$Key" `
-Name "StateFlags0200" `
-PropertyType DWORD `
-Value 0x2 `
-Force `
-ErrorAction SilentlyContinue | Out-Null
}
Write-Output "• Datenträgerbereinigung wird gestartet, dies kann einige Minuten dauern ..."
Start-Process -Wait -FilePath "$env:SystemRoot\System32\cleanmgr.exe" -ArgumentList "/sagerun:200" -NoNewWindow
Write-Output ""
Write-Output "Bereinigung abgeschlossen."
exit 0
}
catch {
Write-Output ""
Write-Output "FEHLER bei der Bereinigung:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 10: Upgrade Windows Home -> Pro (generischer Key)
# -------------------------------------------------------------------------
"upgrade_pro" {
Write-Output "Prüfe Windows-Edition für Upgrade auf Pro ..."
Write-Output ""
try {
$OS = Get-CimInstance Win32_OperatingSystem
$caption = $OS.Caption
Write-Output "Gefundene Edition: $caption"
Write-Output ""
if ($caption -like "*Windows 10 Home*" -or $caption -like "*Windows 11 Home*") {
Write-Output "Setze generischen Windows Pro Product Key (Upgrade) ..."
Changepk.exe /ProductKey VK7JG-NPHTM-C97JM-9MPGT-3V66T
Write-Output ""
Write-Output "Der Key wurde gesetzt. Ein Neustart und anschließende Aktivierung sind ggf. erforderlich."
exit 0
}
else {
Write-Output "Dieses System ist keine unterstützte Home-Edition - Upgrade wird nicht ausgeführt."
exit 0
}
}
catch {
Write-Output ""
Write-Output "FEHLER beim Upgrade-Versuch:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 11: BitLocker auf C: deaktivieren
# -------------------------------------------------------------------------
"bitlocker_disable" {
Write-Output "BitLocker-Verschlüsselung auf Laufwerk C: wird deaktiviert ..."
Write-Output ""
try {
if (Get-Command -Name Get-BitLockerVolume -ErrorAction SilentlyContinue) {
$vol = Get-BitLockerVolume -MountPoint 'C:' -ErrorAction SilentlyContinue
if (-not $vol) {
Write-Output "Für Laufwerk C: wurde kein BitLocker-Volume gefunden."
exit 1
}
if ($vol.ProtectionStatus -eq 0) {
Write-Output "BitLocker ist auf Laufwerk C: bereits deaktiviert."
exit 0
}
Disable-BitLocker -MountPoint 'C:' | Out-Null
Write-Output "BitLocker-Deaktivierung wurde gestartet."
Write-Output "Die Entschlüsselung läuft im Hintergrund und kann je nach Laufwerksgröße lange dauern."
exit 0
}
else {
Write-Output "BitLocker-Cmdlets sind auf diesem System nicht verfügbar."
exit 1
}
}
catch {
Write-Output ""
Write-Output "FEHLER bei der BitLocker-Deaktivierung:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 11: Performance / Höchstleistungsmodus + CPU/USB/Buttons-Optimierung
# -------------------------------------------------------------------------
"power_high" {
Write-Output "Performance-Optimierung wird ausgeführt ..."
Write-Output ""
try {
# Energiesparplan: Höchstleistung aktivieren (GUID 8c5e7fda-...)
$planGUID = "8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"
$powerPlans = powercfg.exe /list
$planExists = $powerPlans -match $planGUID
if (-not $planExists) {
Write-Output "• Höchstleistungsplan nicht gefunden - Standardplan wird dupliziert ..."
powercfg -duplicatescheme "$planGUID" | Out-Null 2>$null
}
Write-Output "• Aktiviere Höchstleistungs-Energieplan ..."
# PreferredPlan in der Systemsteuerung setzen (optional, für UI)
Set-ItemProperty `
-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\ControlPanel\NameSpace\{025A5937-A6BE-4686-A844-36FE4BEC8B6D}' `
-Name PreferredPlan `
-Value $planGUID `
-ErrorAction SilentlyContinue
powercfg -setactive $planGUID | Out-Null
# Ruhezustand deaktivieren
Write-Output "• Deaktiviere Ruhezustand ..."
powercfg -hibernate off | Out-Null
# Mindest-CPU-Zustand
Write-Output "• Optimiere Mindest-CPU-Zustand [AC: 50% | DC: 5%] ..."
# Subgroup: Prozessorenergieverwaltung
# Setting: Mindestprozessorzustand
$subProcessor = "54533251-82be-4824-96c1-47b60b740d00"
$setMinProc = "893dee8e-2bef-41e0-89c6-b55d0929964c"
powercfg -SETACVALUEINDEX SCHEME_CURRENT $subProcessor $setMinProc 5 | Out-Null
powercfg -SETDCVALUEINDEX SCHEME_CURRENT $subProcessor $setMinProc 5 | Out-Null
# Core Parking
Write-Output "• Optimiere Core Parking [AC: 100% | DC: 50%] ..."
# Setting: Prozessor-Leerlaufzustand - Minimaler Prozessorzustand für Core-Parking
$setCoreParking = "0cc5b647-c1df-4637-891a-dec35c318583"
powercfg -SETACVALUEINDEX SCHEME_CURRENT $subProcessor $setCoreParking 50 | Out-Null
powercfg -SETDCVALUEINDEX SCHEME_CURRENT $subProcessor $setCoreParking 30 | Out-Null
# Processor Performance Decrease Time
Write-Output "• Optimiere CPU Decrease Time [AC: 1500ms | DC: 750ms] ..."
$setDecreaseTime = "4d2b0152-7d5c-498b-88e2-34345392a2c5"
powercfg -SETACVALUEINDEX SCHEME_CURRENT $subProcessor $setDecreaseTime 1500 | Out-Null
powercfg -SETDCVALUEINDEX SCHEME_CURRENT $subProcessor $setDecreaseTime 750 | Out-Null
# Processor Performance Decrease Threshold
Write-Output "• Optimiere CPU Decrease Threshold [AC: 20% | DC: 20%] ..."
$setDecreaseThreshold = "12a0ab44-fe28-4fa9-b3bd-4b64f44960a6"
powercfg -SETACVALUEINDEX SCHEME_CURRENT $subProcessor $setDecreaseThreshold 20 | Out-Null
powercfg -SETDCVALUEINDEX SCHEME_CURRENT $subProcessor $setDecreaseThreshold 20 | Out-Null
# Processor Performance Increase Time
Write-Output "• Optimiere CPU Increase Time [AC: 200ms | DC: 200ms] ..."
$setIncreaseTime = "984cf492-3bed-4488-a8f9-4286f832755"
powercfg -SETACVALUEINDEX SCHEME_CURRENT $subProcessor $setIncreaseTime 200 | Out-Null
powercfg -SETDCVALUEINDEX SCHEME_CURRENT $subProcessor $setIncreaseTime 200 | Out-Null
# Festplatten-Timeout
Write-Output "• Optimiere Festplatten-Timeout [AC: 0 Minuten | DC: 15 Minuten] ..."
powercfg -change -disk-timeout-ac 0 | Out-Null
powercfg -change -disk-timeout-dc 15 | Out-Null
# USB selektiver Energiesparmodus
Write-Output "• Optimiere USB-Selektivmodus [AC: Aus | DC: Ein] ..."
$subUsb = "2a737441-1930-4402-8d77-b2bebba308a3"
$setUsbSel = "48e6b7a6-50f5-4782-a5d4-53bb8f07e226"
powercfg -SETACVALUEINDEX SCHEME_CURRENT $subUsb $setUsbSel 0 | Out-Null # aus
powercfg -SETDCVALUEINDEX SCHEME_CURRENT $subUsb $setUsbSel 1 | Out-Null # ein
# Monitor- und Standby-Timeout
Write-Output "• Optimiere Monitor/Standby-Timeout [AC: 0 Min | DC: 10 Min (Monitor)] ..."
powercfg -change -standby-timeout-ac 0 | Out-Null
powercfg -change -standby-timeout-dc 0 | Out-Null
powercfg -change -monitor-timeout-ac 0 | Out-Null
powercfg -change -monitor-timeout-dc 10 | Out-Null
# Tasten-/Deckel-Aktionen (sub_buttons)
$subButtons = "sub_buttons"
Write-Output "• Optimiere Aktion beim Schließen des Notebook-Deckels [AC/DC: Nichts tun] ..."
$lidAction = "5ca83367-6e45-459f-a27b-476b1d01c936"
powercfg -setdcvalueindex scheme_current $subButtons $lidAction 0 | Out-Null
powercfg -setacvalueindex scheme_current $subButtons $lidAction 0 | Out-Null
Write-Output "• Optimiere Schlaftaste [AC/DC: Nichts tun] ..."
$sleepAction = "96996bc0-ad50-47ec-923b-6f41874dd9eb"
powercfg -setdcvalueindex scheme_current $subButtons $sleepAction 0 | Out-Null
powercfg -setacvalueindex scheme_current $subButtons $sleepAction 0 | Out-Null
Write-Output "• Optimiere Ein-/Ausschalter [AC/DC: Herunterfahren] ..."
$powerButton = "7648efa3-dd9c-4e3e-b566-50f929386280"
powercfg -setdcvalueindex scheme_current $subButtons $powerButton 3 | Out-Null
powercfg -setacvalueindex scheme_current $subButtons $powerButton 3 | Out-Null
# Optionale weitere Tasten-/UI-Anpassung wie im Original
$extraButtons = "a7066653-8d6c-40a8-910e-a1f54b84c7e5"
powercfg -setdcvalueindex scheme_current $subButtons $extraButtons 2 | Out-Null
powercfg -setacvalueindex scheme_current $subButtons $extraButtons 2 | Out-Null
# Aktuellen Plan mit allen Änderungen aktiv setzen
powercfg /setactive SCHEME_CURRENT | Out-Null
# Hintergrund-Apps deaktivieren (wie im Originalscript)
Write-Output "• Deaktiviere Hintergrundzugriff für ausgewählte Apps ..."
$apps = @(
"Microsoft.MicrosoftEdge.Stable_8wekyb3d8bbwe",
"Microsoft.Microsoft3DViewer_8wekyb3d8bbwe",
"Microsoft.WindowsAlarms_8wekyb3d8bbwe",
"Microsoft.WindowsCalculator_8wekyb3d8bbwe",
"Microsoft.WindowsCamera_8wekyb3d8bbwe",
"Microsoft.549981C3F5F10_8wekyb3d8bbwe",
"Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe",
"Microsoft.GetHelp_8wekyb3d8bbwe",
"Microsoft.ZuneMusic_8wekyb3d8bbwe",
"microsoft.windowscommunicationsapps_8wekyb3d8bbwe",
"Microsoft.WindowsMaps_8wekyb3d8bbwe",
"Microsoft.MicrosoftSolitaireCollection_8wekyb3d8bbwe",
"Microsoft.WindowsStore_8wekyb3d8bbwe",
"Microsoft.ZuneVideo_8wekyb3d8bbwe",
"Microsoft.MicrosoftOfficeHub_8wekyb3d8bbwe",
"Microsoft.Office.OneNote_8wekyb3d8bbwe",
"Microsoft.MSPaint_8wekyb3d8bbwe",
"Microsoft.People_8wekyb3d8bbwe",
"Microsoft.Windows.Photos_8wekyb3d8bbwe",
"windows.immersivecontrolpanel_cw5n1h2txyewy",
"Microsoft.SkypeApp_kzf8qxf38zg5c",
"Microsoft.ScreenSketch_8wekyb3d8bbwe",
"Microsoft.MicrosoftStickyNotes_8wekyb3d8bbwe",
"Microsoft.Getstarted_8wekyb3d8bbwe",
"Microsoft.WindowsSoundRecorder_8wekyb3d8bbwe",
"Microsoft.BingWeather_8wekyb3d8bbwe",
"Microsoft.XboxApp_8wekyb3d8bbwe",
"Microsoft.YourPhone_8wekyb3d8bbwe",
"Microsoft.MixedReality.Portal_8wekyb3d8bbwe",
"Microsoft.Xbox.TCUI_8wekyb3d8bbwe"
)
foreach ($app in $apps) {
$path = "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\BackgroundAccessApplications\$app"
if (!(Test-Path $path)) {
New-Item -Path $path -Force | Out-Null
}
Set-ItemProperty -Path $path -Name "Disabled" -Value 1 -Type DWord
Set-ItemProperty -Path $path -Name "DisabledByUser" -Value 1 -Type DWord
}
Write-Output ""
Write-Output "Performance-Optimierung abgeschlossen."
Write-Output "Hinweis: Einige Einstellungen (Tasten/Deckel) wirken sich v. a. auf Notebooks aus."
exit 0
}
catch {
Write-Output ""
Write-Output "FEHLER bei der Performance-Optimierung:"
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 12: Akkuinformationen anzeigen
# -------------------------------------------------------------------------
"battery_info" {
Write-Output "Akkuzustand wird analysiert ..."
Write-Output ""
if ($true) {
$batteries = Get-CimInstance -ClassName Win32_Battery -ErrorAction SilentlyContinue
if (-not $batteries) {
Write-ToolStatus "INFO" "Kein Akku erkannt - Akkudiagnose wurde übersprungen."
exit 0
}
$desktop = [Environment]::GetFolderPath('Desktop')
if (-not $desktop) { $desktop = "$env:USERPROFILE\Desktop" }
$reportName = "SD-ITLab-BatteryReport.html"
$reportPath = Join-Path $desktop $reportName
Write-Output "Erstelle Windows-Batteriereport ..."
Write-Output " Ziel: $reportPath"
Write-Output ""
$null = powercfg /batteryreport /output "$reportPath" /format HTML 2>$null
$staticItems = @(Get-WmiObject -Class "BatteryStaticData" -Namespace "ROOT\WMI" -ErrorAction SilentlyContinue)
$fullItems = @(Get-WmiObject -Class "BatteryFullChargedCapacity" -Namespace "ROOT\WMI" -ErrorAction SilentlyContinue)
$cycleItems = @(Get-WmiObject -Class "BatteryCycleCount" -Namespace "ROOT\WMI" -ErrorAction SilentlyContinue)
Write-Output ("Erkannte Akkus: {0}" -f @($batteries).Count)
Write-Output ""
$index = 0
foreach ($battery in @($batteries)) {
$index++
$static = $staticItems | Select-Object -Index ($index - 1) -ErrorAction SilentlyContinue
$full = $fullItems | Select-Object -Index ($index - 1) -ErrorAction SilentlyContinue
$cycle = $cycleItems | Select-Object -Index ($index - 1) -ErrorAction SilentlyContinue
$batteryName = "Unbekannt"
if ($battery.Name) { $batteryName = $battery.Name }
Write-Output ("Akku {0}: {1}" -f $index, $batteryName)
$design = $null
$fullCap = $null
if ($static -and $static.DesignedCapacity -gt 0) { $design = [double]$static.DesignedCapacity }
if ($full -and $full.FullChargedCapacity -gt 0) { $fullCap = [double]$full.FullChargedCapacity }
if ($design) { Write-Output (" Designkapazität: {0:N0} mWh" -f $design) }
if ($fullCap) { Write-Output (" Volle Ladekapazität: {0:N0} mWh" -f $fullCap) }
if ($design -and $fullCap -and $design -gt 0) {
$health = [math]::Round(($fullCap * 100.0 / $design), 1)
if ($health -ge 80) {
Write-ToolStatus "OK" ("Akku-Gesundheit: {0} %" -f $health)
} elseif ($health -ge 60) {
Write-ToolStatus "WARNUNG" ("Akku-Gesundheit: {0} %" -f $health)
} else {
Write-ToolStatus "KRITISCH" ("Akku-Gesundheit: {0} %" -f $health)
}
} else {
Write-ToolStatus "INFO" "Herstellerdaten für Design- oder Ladekapazität sind nicht vollständig verfügbar."
}
if ($cycle -and $cycle.CycleCount -ne $null) {
Write-Output (" Ladezyklen: {0}" -f $cycle.CycleCount)
}
Write-Output ""
}
Write-Output "Hinweis: Akkudaten werden vom Gerät bzw. Hersteller bereitgestellt und können unvollständig sein."
Write-Output "Der vollständige Windows-Batteriereport wurde gespeichert:"
Write-Output " $reportPath"
exit 0
}
catch {
Write-ToolStatus "FEHLER" "Akkuzustand konnte nicht ermittelt werden."
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 13: Geräte- und Treiberprobleme prüfen (read-only)
# -------------------------------------------------------------------------
"device_driver_check" {
Write-Output "Geräte- und Treiberprobleme werden geprüft ..."
Write-Output ""
try {
if (-not (Get-Command Get-PnpDevice -ErrorAction SilentlyContinue)) {
Write-ToolStatus "INFO" "Get-PnpDevice ist auf diesem System nicht verfügbar."
exit 0
}
$devices = @(Get-PnpDevice -PresentOnly -ErrorAction Stop | Where-Object {
$_.Problem -ne $null -and [int]$_.Problem -ne 0
})
if ($devices.Count -eq 0) {
Write-ToolStatus "OK" "Keine vorhandenen Geräte mit Windows-Problemcode erkannt."
exit 0
}
$critical = @($devices | Where-Object { [int]$_.Problem -eq 43 })
if ($critical.Count -gt 0) {
Write-ToolStatus "KRITISCH" ("{0} Gerät(e) mit kritischem Problemcode erkannt." -f $critical.Count)
} else {
Write-ToolStatus "WARNUNG" ("{0} Gerät(e) mit Problemcode erkannt." -f $devices.Count)
}
Write-Output ""
foreach ($device in $devices) {
$code = [int]$device.Problem
Write-ToolStatus (Get-DeviceProblemLevel $code) ("{0} (Code {1})" -f $device.FriendlyName, $code)
Write-Output (" Klasse: {0}" -f $device.Class)
Write-Output (" Status: {0}" -f $device.Status)
Write-Output (" Bedeutung: {0}" -f (Get-DeviceProblemText $code))
Write-Output (" Instance-ID: {0}" -f $device.InstanceId)
Write-Output ""
}
exit 0
}
catch {
Write-ToolStatus "FEHLER" "Geräte- und Treiberdiagnose konnte nicht abgeschlossen werden."
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 14: Speicherplatz prüfen (read-only)
# -------------------------------------------------------------------------
"disk_space_check" {
Write-Output "Speicherplatz lokaler Laufwerke wird geprüft ..."
Write-Output ""
try {
$volumes = @(Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" -ErrorAction Stop |
Where-Object { $_.DeviceID -and $_.Size -and $_.Size -ge 5GB })
if ($volumes.Count -eq 0) {
Write-ToolStatus "INFO" "Keine bewertbaren lokalen Dateisystemlaufwerke gefunden."
exit 0
}
foreach ($vol in $volumes) {
$size = [double]$vol.Size
$free = [double]$vol.FreeSpace
$used = $size - $free
$freePct = [math]::Round(($free * 100.0 / $size), 1)
if ($freePct -lt 8) {
$level = "KRITISCH"
$msg = ("{0} nur noch {1}% frei" -f $vol.DeviceID, $freePct)
} elseif ($freePct -lt 15) {
$level = "WARNUNG"
$msg = ("{0} nur noch {1}% frei" -f $vol.DeviceID, $freePct)
} else {
$level = "OK"
$msg = ("{0} {1}% freier Speicher" -f $vol.DeviceID, $freePct)
}
Write-ToolStatus $level $msg
$fileSystem = "Unbekannt"
if ($vol.FileSystem) { $fileSystem = $vol.FileSystem }
Write-Output (" Dateisystem: {0}" -f $fileSystem)
Write-Output (" Gesamt: {0}" -f (Format-ToolSize $size))
Write-Output (" Belegt: {0}" -f (Format-ToolSize $used))
Write-Output (" Frei: {0}" -f (Format-ToolSize $free))
Write-Output ""
}
exit 0
}
catch {
Write-ToolStatus "FEHLER" "Speicherplatzprüfung konnte nicht abgeschlossen werden."
Write-Output $_.Exception.Message
exit 1
}
}
# -------------------------------------------------------------------------
# 15: Ausstehenden Neustart erkennen (read-only)
# -------------------------------------------------------------------------
"pending_reboot_check" {