소스 검색

New check for OneDrive Files existence 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 년 전
부모
커밋
03a2513079
1개의 변경된 파일30개의 추가작업 그리고 0개의 파일을 삭제
  1. 30 0
      Windows10Debloater.ps1

+ 30 - 0
Windows10Debloater.ps1

@@ -518,6 +518,36 @@ Function FixWhitelistedApps {
 
 Function UninstallOneDrive {
 
+    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-Output "Uninstalling OneDrive"
     
     New-PSDrive  HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT