From 5db2bcd378b4b83efaba7793fa68f368b71a8612 Mon Sep 17 00:00:00 2001 From: Richard Newton Date: Fri, 25 Jan 2019 20:20:35 -0800 Subject: [PATCH] Added Self elevation to run as administrator I added code to perform self elevation asking for the script to be run as an Administrator, otherwise the script will not be able to perform at its best. This resolves issue #73 --- Windows10Debloater.ps1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Windows10Debloater.ps1 b/Windows10Debloater.ps1 index 795c6ec..1355e1a 100644 --- a/Windows10Debloater.ps1 +++ b/Windows10Debloater.ps1 @@ -1,6 +1,15 @@ #This function finds any AppX/AppXProvisioned package and uninstalls it, except for Freshpaint, Windows Calculator, Windows Store, and Windows Photos. #Also, to note - This does NOT remove essential system services/software/etc such as .NET framework installations, Cortana, Edge, etc. +#This will self elevate the script so with a UAC prompt since this script needs to be run as an Administrator in order to function properly. +If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + $arguments = "&" + $MyInvocation.MyCommand.Definition + "" + Write-Host "You didn't run this script as an Administrator. This script will self elevate to run as an Administrator." -ForegroundColor "White" + Start-Sleep 1 + Start-Process "powershell.exe" -Verb RunAs -ArgumentList $arguments + Break +} + #no errors throughout $ErrorActionPreference = 'silentlycontinue'