-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsRepairBund.ps1
More file actions
111 lines (105 loc) · 4.88 KB
/
WindowsRepairBund.ps1
File metadata and controls
111 lines (105 loc) · 4.88 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
$title = 'Starting Administrative Windows Repairs'
$question = 'Are you sure you want to proceed?'
$choices = '&Yes', '&No'
$title2 = 'Would you like to install the new version of Powershell?'
$title3 = 'Are you on windows 10?'
$title4 = 'Would you like to create a restore point?'
$title5 = 'Would you like to repair windows update services?'
$url2 = "https://go.microsoft.com/fwlink/?LinkID=799445"
$folder2 = "$env:appdata\WUA"
function Test-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test-Admin) -eq $false) {
if ($elevated) {
# tried to elevate, did not work, aborting
} else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -executionpolicy bypass -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
$decision = $Host.UI.PromptForChoice($title3, $question, $choices, 1)
if ($decision -eq 0) {
Write-Host 'confirmed'
if (Test-Path -Path $folder2) {Write-Host "WUA directory already exists, removing old version"
Remove-Item -Path $folder2 -Recurse
New-Item -Path "$env:appdata\" -Name "WUA" -ItemType "directory"
Invoke-WebRequest $url2 -OutFile "$folder2\WUA.exe"
Start-Process "$folder2\WUA.exe"}
else {
New-Item -Path "$env:appdata\" -Name "WUA" -ItemType "directory"
Invoke-WebRequest $url2 -OutFile "$folder2\WUA.exe"
Start-Process "$folder2\WUA.exe"}
}
else {
Write-Host 'cancelled'
}
$decision = $Host.UI.PromptForChoice($title2, $question, $choices, 1)
if ($decision -eq 0) {
Write-Host 'confirmed'
$url3 = "https://github.com/PowerShell/PowerShell/releases/download/v7.2.6/PowerShell-7.2.6-win-x64.msi"
$folder3 = "$env:Temp\pwsh"
if (Test-Path -Path $folder3) { Write-Host "pwsh directory already exists, skipping" }
else {
New-Item -Path "$env:temp\" -Name "pwsh" -ItemType "directory"
Invoke-WebRequest $url3 -OutFile "$folder3\pwsh.msi"
Start-Process "$folder3\pwsh.msi" -ArgumentList "/quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ENABLE_PSREMOTING=0 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1 ADD_PATH=1"}
}
else {
Write-Host 'cancelled'
}
$registrykey = "HKLM:\System\CurrentControlSet\Services\VSS\VssAccessControl\$name"
$name = "$env:UserDomain\$env:UserName"
$value = "1"
$decision = $Host.UI.PromptForChoice($title4, $question, $choices, 1)
if ($decision -eq 0) {
Write-Host 'confirmed, attempting to create restore point'
try {Enable-ComputerRestore -drive C:\
Invoke-CimMethod -Namespace root/DEFAULT -ClassName SystemRestore -MethodName CreateRestorePoint -Arguments @{
Description = (Get-Date).ToString()
RestorePointType = [uint32]0
EventType = [uint32]100
}Checkpoint-Computer -Description myrecovery}
catch { "unable to create restore point, adding manual registry key"
if (test-path -path $registrykey){
Write-host "user already has VSS service access" }
else { New-Item -path $registrykey -Force | Out-Null
New-ItemProperty -path $registrykey -name $name -value $value -propertytype DWORD -force | Out-Null
}}
try{Checkpoint-Computer -Description myrecovery}
catch{ "error creating restore point, launching gui and attempting shell recovery"
Start-Process -FilePath "${env:Windir}\System32\cmd.EXE" -ArgumentList '/c Wmic.exe /Namespace:\\root\default Path SystemRestore Call CreateRestorePoint "My Restore Point", 100, 7
' -Wait -Verb RunAs
Start-Process -Filepath "${env:Windir}\System32\rstrui.exe"
Start-Process -Filepath "${env:Windir}\System32\SystemPropertiesProtection.exe"}
}
else {
Write-Host 'cancelled'
}
$decision = $Host.UI.PromptForChoice($title5, $question, $choices, 1)
if ($decision -eq 0) {
Invoke-Webrequest -uri https://raw.githubusercontent.com/harryeetsource/WindowsScripts/9ddb625d7bcf939175a027930d9195ad1565a628/WuReset2.0.bat -OutFile "${env:temp}\wu.bat"
Start-Process -Filepath "${env:temp}\wu.bat"
}
else {
Write-Host 'cancelled'
}
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
if ($decision -eq 0) {
Write-Host 'confirmed'
try {
Repair-WindowsImage -Online -Restorehealth -Startcomponentcleanup -ResetBase
}
catch { 'Issues with provided argument, starting basic windows repair.'
{1: Repair-WindowsImage -Online -Restorehealth}
}
Get-AppXPackage -AllUsers | Foreach-Object {Add-AppxPackage -DisableDevelopmentMode -Register -ErrorAction SilentlyContinue "$($_.InstallLocation)\AppXManifest.xml"}
Start-Process -FilePath "${env:Windir}\System32\cmd.EXE" -ArgumentList '/c sfc /scannow Pause' -Wait -Verb RunAs
}
else {
Write-Host 'cancelled'
}
Write-Host 'Admin updates completed.'
Pause