-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ps1
39 lines (37 loc) · 1.64 KB
/
test.ps1
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
$title = 'Starting Administrative Windows Repairs'
$question = 'Are you sure you want to proceed?'
$choices = '&Yes', '&No'
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
if ($decision -eq 0) {
Write-Host 'confirmed'
$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
}
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"}
Repair-WindowsImage -Online -Restorehealth -Startcomponentcleanup -ResetBase
Get-AppXPackage -AllUsers | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register -ErrorAction SilentlyContinue "$($_.InstallLocation)\AppXManifest.xml"}
sfc.exe /scannow
}
else {
Write-Host 'cancelled'
}