瀏覽代碼

New check for OneDrive files and folder existence

I added code to check for the OneDrive folder and its files before removal. If it finds that the folder exists, it will then check to see if there are files inside of the folder. If there are no files then OneDrive is uninstalled.

If there are files, then it creates a new folder called OneDriveBackupFiles on the user's desktop, move all of the files into that folder, and then removes OneDrive. 

This is a safety measure after a user had their OneDrive files (unfortunately) deleted from their machine.
Richard Newton 6 年之前
父節點
當前提交
df582d0793
共有 1 個文件被更改,包括 34 次插入4 次删除
  1. 34 4
      Windows10DebloaterGUI.ps1

+ 34 - 4
Windows10DebloaterGUI.ps1

@@ -476,10 +476,10 @@ $RemoveAllBloatware.Add_Click( {
         Function CheckInstallService {
   
             If (Get-Service -Name InstallService | Where-Object {$_.Status -eq "Stopped"}) {  
-              Start-Service -Name InstallService
-              Set-Service -Name InstallService -StartupType Automatic 
-              }
-          }
+                Start-Service -Name InstallService
+                Set-Service -Name InstallService -StartupType Automatic 
+            }
+        }
   
         Write-Host "Initiating Sysprep"
         Begin-SysPrep
@@ -1151,6 +1151,36 @@ $RemoveRegkeys.Add_Click( {
         Write-Host "Additional bloatware keys have been removed! `n"
     })
 $RemoveOnedrive.Add_Click( { 
+        Write-Output "Checking for pre-existing files located in the OneDrive folders..."
+        Start-Sleep 1
+        If (Get-Item -Path "$env:USERPROFILE\OneDrive\*") {
+            Write-Output "Files found within the OneDrive folder! Checking to see if a folder named OneDriveBackupFiles exists."
+            Start-Sleep 1
+              
+            If (Get-Item "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -ErrorAction SilentlyContinue) {
+                Write-Output "A folder named OneDriveBackupFiles already exists on your desktop. All files from your OneDrive location will be moved to that folder." 
+            }
+            else {
+                If (!(Get-Item "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -ErrorAction SilentlyContinue)) {
+                    Write-Output "A folder named OneDriveBackupFiles will be created and will be located on your desktop. All files from your OneDrive location will be located in that folder."
+                    New-item -Path "$env:USERPROFILE\Desktop" -Name "OneDriveBackupFiles"-ItemType Directory -Force
+                    Write-Output "Successfully created the folder 'OneDriveBackupFiles' on your desktop."
+                }
+            }
+            Start-Sleep 1
+            Move-Item -Path "$env:USERPROFILE\OneDrive\*" -Destination "$env:USERPROFILE\Desktop\OneDriveBackupFiles" -Force
+            Write-Output "Successfully moved all files from your OneDrive folder to the folder 'OneDriveBackupFiles' on your desktop."
+            Start-Sleep 1
+            Write-Output "Proceeding with the removal of OneDrive."
+            Start-Sleep 1
+        }
+        Else {
+            If (!(Get-Item -Path "$env:USERPROFILE\OneDrive\*")) {
+                Write-Output "Either the OneDrive folder does not exist or there are no files to be found in the folder. Proceeding with removal of OneDrive."
+                Start-Sleep 1
+            }
+        }
+
         Write-Host "Uninstalling OneDrive. Please wait..."
     
         New-PSDrive  HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT