Browse Source

Changed Start-Debloat Function Code, new function

I changed the Start-Debloat Function's code to use [regex] as explained in the following link: https://www.reddit.com/r/PowerShell/comments/7xzwah/4_whitelisted_apps_in_my_script_are_being_removed/\

Thanks to Reddit user /u/GavinEke for the help.

I added a new Function called FixWhitelistedApps which will run and check to see if the Whitelisted apps in the Start-Debloat function were removed, and if so it should bring them back.
Richard Newton 7 years ago
parent
commit
13a0d7c03e
1 changed files with 25 additions and 14 deletions
  1. 25 14
      Windows10Debloater.ps1

+ 25 - 14
Windows10Debloater.ps1

@@ -18,20 +18,9 @@ Function Start-Debloat {
     Param()
     
     #Removes AppxPackages
-    Get-AppxPackage -AllUsers | 
-        Where-Object {$_.name -notcontains "Microsoft.Paint3D"} | 
-        Where-Object {$_.name -notcontains "Microsoft.WindowsCalculator"} |
-        Where-Object {$_.name -notcontains "Microsoft.WindowsStore"} | 
-        Where-Object {$_.name -notcontains "Microsoft.Windows.Photos"} |
-        Remove-AppxPackage -ErrorAction SilentlyContinue
-            
-    #Removes AppxProvisionedPackages
-    Get-AppxProvisionedPackage -online |
-        Where-Object {$_.packagename -notcontains "Microsoft.Paint3D"} |
-        Where-Object {$_.packagename -notcontains "Microsoft.WindowsCalculator"} |
-        Where-Object {$_.packagename -notcontains "Microsoft.WindowsStore"} |
-        Where-Object {$_.packagename -notcontains "Microsoft.Windows.Photos"} |
-        Remove-AppxProvisionedPackage -online -ErrorAction SilentlyContinue
+    [regex]$WhitelistedApps = 'Microsoft.Paint3D|Microsoft.WindowsCalculator|Microsoft.WindowsStore|Microsoft.Windows.Photos'
+    Get-AppxPackage -AllUsers | Where-Object {$_.Name -NotMatch $WhitelistedApps} | Remove-AppxPackage -ErrorAction SilentlyContinue
+    Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -NotMatch $WhitelistedApps} | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
 }
 Function Remove-Keys {
         
@@ -343,6 +332,19 @@ Function Enable-EdgePDF {
     }
 }
 
+Function FixWhitelistedApps {
+    
+    [CmdletBinding()]
+            
+    Param()
+    
+    If(!(Get-AppxPackage -AllUsers | Select Microsoft.Paint3D, Microsoft.WindowsCalculator, Microsoft.WindowsStore, Microsoft.Windows.Photos)) {
+    
+    Get-AppxPackage -allusers Microsoft.Paint3D | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
+    Get-AppxPackage -allusers Microsoft.WindowsCalculator | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
+    Get-AppxPackage -allusers Microsoft.WindowsStore | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}
+    Get-AppxPackage -allusers Microsoft.Windows.Photos | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"} } }
+
 #This switch will ask you if you'd like to run the script as interactive or silently. Depending on your selection, yes will be interactive, no will be silent.
 Write-Output "How would you like to run this script?"
 $ReadHost = Read-Host " ( Interactive / Noninteractive ) "
@@ -367,6 +369,10 @@ Switch ($ReadHost) {
                 Remove-Keys
                 Write-Output "Leftover bloatware registry keys removed."
                 Sleep 1
+                Write-Output "Checking to see if any Whitelisted Apps were removed, and if so re-adding them."
+                Sleep 1
+                FixWhitelistedApps
+                Sleep 1
                 Write-Output "Disabling Cortana from search, disabling feedback to Microsoft, and disabling scheduled tasks that are considered to be telemetry or unnecessary."
                 Protect-Privacy
                 Write-Output "Cortana disabled from search, feedback to Microsoft has been disabled, and scheduled tasks are disabled."
@@ -457,6 +463,11 @@ Switch ($ReadHost) {
                 Write-Output "Removing leftover bloatware registry keys."
                 Sleep 1
                 Remove-Keys
+                Sleep 1
+                Write-Output "Checking to see if any Whitelisted Apps were removed, and if so re-adding them."
+                Sleep 1
+                FixWhitelistedApps
+                Sleep 1
                 Write-Output "Stopping Edge from being used as the default PDF Viewer."
                 Sleep 1
                 Protect-Privacy