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.
pull/82/head
Richard Newton 6 years ago committed by GitHub
parent 03a2513079
commit df582d0793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

Loading…
Cancel
Save